Bird
0
0

Identify the error in this custom pipe code:

medium📝 Debug Q14 of 15
NestJS - Pipes

Identify the error in this custom pipe code:

import { PipeTransform, Injectable } from '@nestjs/common';

@Injectable()
export class UppercasePipe implements PipeTransform {
  transform(value: string) {
    return value.toUpperCase;
  }
}
AMissing @Injectable decorator
Btransform method missing return type
CtoUpperCase is used without parentheses
DPipeTransform interface not implemented
Step-by-Step Solution
Solution:
  1. Step 1: Check the transform method implementation

    The method returns value.toUpperCase without parentheses, which is a reference to the function, not the result.
  2. Step 2: Identify correct usage of toUpperCase

    toUpperCase is a method and must be called with parentheses: value.toUpperCase()
  3. Final Answer:

    toUpperCase is used without parentheses -> Option C
  4. Quick Check:

    Method calls need () to execute [OK]
Quick Trick: Remember to call string methods with () [OK]
Common Mistakes:
  • Forgetting parentheses on method calls
  • Assuming decorators are missing when present
  • Ignoring interface implementation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes