Bird
0
0

Given this DTO and ValidationPipe setup, what will be the output when sending { "age": "25" } in the request body?

medium📝 component behavior Q13 of 15
NestJS - Pipes
Given this DTO and ValidationPipe setup, what will be the output when sending { "age": "25" } in the request body?
class UserDto {
  @IsInt()
  age: number;
}

// In controller
@Post()
create(@Body(new ValidationPipe({ transform: true })) user: UserDto) {
  return typeof user.age;
}
A"string"
B"undefined"
CValidation error thrown
D"number"
Step-by-Step Solution
Solution:
  1. Step 1: Check ValidationPipe transform option

    Transform is true, so input string "25" will be converted to number 25.
  2. Step 2: Determine returned type

    Since age is transformed to number, typeof user.age returns "number".
  3. Final Answer:

    "number" -> Option D
  4. Quick Check:

    transform converts string to number, so typeof = "number" [OK]
Quick Trick: transform: true converts strings to numbers automatically [OK]
Common Mistakes:
  • Assuming input stays string without transform
  • Expecting validation error for string number
  • Thinking age is undefined without explicit conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes