Bird
0
0

Identify the error in this custom pipe code:

medium📝 Debug Q6 of 15
NestJS - Pipes
Identify the error in this custom pipe code:
import { PipeTransform } from '@nestjs/common';
export class MyPipe implements PipeTransform {
transform(value) {
return value.toUpperCase();
}
}
AMissing type annotation for transform method parameter
BPipeTransform interface is not imported correctly
CClass should be decorated with @Injectable()
DtoUpperCase() cannot be called on all types of value
Step-by-Step Solution
Solution:
  1. Step 1: Analyze transform method usage

    Calling toUpperCase() assumes value is a string, but input can be any type.
  2. Step 2: Identify the problem with calling toUpperCase()

    If value is not a string, this will cause a runtime error.
  3. Final Answer:

    toUpperCase() cannot be called on all types of value -> Option D
  4. Quick Check:

    Ensure input type matches method calls [OK]
Quick Trick: Check input type before string methods [OK]
Common Mistakes:
  • Ignoring input type safety
  • Assuming all inputs are strings
  • Forgetting to decorate pipe with @Injectable() (optional)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes