Bird
0
0

Given this DTO:

medium📝 component behavior Q4 of 15
NestJS - Pipes
Given this DTO:
class UserDto {  @IsInt()  age: number;}

And ValidationPipe with transform: true, what happens when the input is { "age": "30" }?
AThe string "30" is converted to number 30 and passes validation
BValidation fails because age is a string, not a number
CValidationPipe throws a runtime error
DThe input is accepted as string without conversion
Step-by-Step Solution
Solution:
  1. Step 1: Understand transform option effect

    With transform: true, ValidationPipe converts input types to match DTO properties.
  2. Step 2: Apply to input data

    The string "30" is converted to number 30, which satisfies the @IsInt() validation.
  3. Final Answer:

    The string "30" is converted to number 30 and passes validation -> Option A
  4. Quick Check:

    transform: true converts strings to numbers [OK]
Quick Trick: transform: true converts input types automatically [OK]
Common Mistakes:
  • Assuming string input always fails validation
  • Expecting runtime errors on type mismatch
  • Ignoring transform option effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes