Bird
0
0

Identify the issue in this NestJS controller method:

medium📝 Debug Q6 of 15
NestJS - Pipes
Identify the issue in this NestJS controller method:
async getUser(@Query('id', DefaultValuePipe(100)) id: number) { return id; }
AThe parameter <code>id</code> should not have a pipe applied.
BThe default value 100 is not a valid number.
CDefaultValuePipe is not instantiated with the <code>new</code> keyword.
DThe method must be synchronous to use DefaultValuePipe.
Step-by-Step Solution
Solution:
  1. Step 1: Check pipe instantiation

    In NestJS, pipes must be instantiated using the new keyword.
  2. Step 2: Identify the error

    The code uses DefaultValuePipe(100) without new, which causes a runtime error.
  3. Final Answer:

    DefaultValuePipe is not instantiated with the new keyword. -> Option C
  4. Quick Check:

    Always instantiate pipes with new [OK]
Quick Trick: Always use 'new' when applying pipes [OK]
Common Mistakes:
  • Omitting 'new' keyword when applying pipes
  • Assuming default value must be a string
  • Thinking async methods cannot use pipes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes