Bird
0
0

Which of the following is the correct way to use ParseIntPipe in a NestJS controller method parameter?

easy📝 Syntax Q12 of 15
NestJS - Pipes
Which of the following is the correct way to use ParseIntPipe in a NestJS controller method parameter?
A@Body('id', ParseIntPipe) id: string
B@Param('id', ParseIntPipe) id: string
C@Param('id', ParseIntPipe) id: number
D@Query('id', ParseIntPipe) id: boolean
Step-by-Step Solution
Solution:
  1. Step 1: Check the parameter decorator and pipe usage

    Using @Param('id', ParseIntPipe) applies the pipe to convert the 'id' route parameter.
  2. Step 2: Match the parameter type with the pipe's output

    ParseIntPipe converts input to a number, so the parameter type must be number.
  3. Final Answer:

    @Param('id', ParseIntPipe) id: number -> Option C
  4. Quick Check:

    ParseIntPipe converts to number, so type = number [OK]
Quick Trick: ParseIntPipe means parameter type must be number [OK]
Common Mistakes:
  • Using string type with ParseIntPipe
  • Applying pipe to wrong decorator like @Body for route param
  • Assigning boolean type with ParseIntPipe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes