Bird
0
0

Which of the following is the correct way to define a custom pipe class in NestJS?

easy📝 Syntax Q12 of 15
NestJS - Pipes

Which of the following is the correct way to define a custom pipe class in NestJS?

export class MyPipe implements PipeTransform {
  transform(value: any, metadata: ArgumentMetadata) {
    // logic here
  }
}
Aexport class MyPipe implements PipeTransform { transform(value: any) { } }
Bexport class MyPipe implements PipeTransform { transform(value: any, metadata: ArgumentMetadata) { } }
Cexport function MyPipe(value: any) { return value; }
Dexport class MyPipe { transform(value: any, metadata: ArgumentMetadata) { } }
Step-by-Step Solution
Solution:
  1. Step 1: Recall the PipeTransform interface signature

    The transform method must accept two parameters: value and metadata of type ArgumentMetadata.
  2. Step 2: Check which option matches the correct method signature

    export class MyPipe implements PipeTransform { transform(value: any, metadata: ArgumentMetadata) { } } correctly implements the transform method with both parameters and the class implements PipeTransform.
  3. Final Answer:

    export class MyPipe implements PipeTransform { transform(value: any, metadata: ArgumentMetadata) { } } -> Option B
  4. Quick Check:

    transform(value, metadata) = correct signature [OK]
Quick Trick: transform method needs value and metadata parameters [OK]
Common Mistakes:
  • Omitting the metadata parameter
  • Using a function instead of a class
  • Not implementing PipeTransform interface

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes