Bird
0
0

This code throws an error when sending /true to

medium📝 Debug Q7 of 15
NestJS - Pipes
This code throws an error when sending /true to
@Get(':flag')
check(@Param('flag', ParseIntPipe) flag: number) { return flag; }
What is the fix?
ARemove the pipe entirely
BChange parameter type to string
CReplace ParseIntPipe with ParseBoolPipe
DUse ValidationPipe instead
Step-by-Step Solution
Solution:
  1. Step 1: Understand why error occurs

    Sending 'true' to ParseIntPipe causes conversion failure because 'true' is not a number.
  2. Step 2: Choose correct pipe for boolean strings

    Replacing ParseIntPipe with ParseBoolPipe correctly converts 'true' or 'false' strings to boolean values.
  3. Final Answer:

    Replace ParseIntPipe with ParseBoolPipe -> Option C
  4. Quick Check:

    Use ParseBoolPipe for boolean string params [OK]
Quick Trick: Use ParseBoolPipe for 'true'/'false' strings [OK]
Common Mistakes:
  • Keeping ParseIntPipe for boolean strings
  • Changing type to string without pipe
  • Removing pipe causing no conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes