Bird
0
0

Which of the following is the correct way to apply DefaultValuePipe to a query parameter named page with a default of 1?

easy📝 Conceptual Q2 of 15
NestJS - Pipes
Which of the following is the correct way to apply DefaultValuePipe to a query parameter named page with a default of 1?
A@Query('page', new DefaultValuePipe) page: number = 1
B@Query('page', new DefaultValuePipe(1)) page: number
C@Query('page', DefaultValuePipe) page: number = 1
D@Query('page', DefaultValuePipe(1)) page: number
Step-by-Step Solution
Solution:
  1. Step 1: Check correct instantiation of DefaultValuePipe

    DefaultValuePipe must be instantiated with new and passed the default value.
  2. Step 2: Verify syntax for @Query decorator

    The correct syntax is @Query('param', new DefaultValuePipe(defaultValue)) param: type.
  3. Final Answer:

    @Query('page', new DefaultValuePipe(1)) page: number -> Option B
  4. Quick Check:

    Use new DefaultValuePipe(default) in decorator [OK]
Quick Trick: Always use 'new' with DefaultValuePipe [OK]
Common Mistakes:
  • Omitting 'new' keyword when creating DefaultValuePipe
  • Assigning default value directly in parameter instead of pipe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes