Bird
0
0

What is wrong with this custom pipe implementation?

medium📝 Debug Q7 of 15
NestJS - Pipes

What is wrong with this custom pipe implementation?

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

@Injectable()
export class TrimPipe implements PipeTransform {
  transform(value: any) {
    value.trim();
    return value;
  }
}
ANo @Injectable() decorator present
BThe trim() result is not returned, original value unchanged
CMissing ArgumentMetadata parameter in transform method
Dtransform method should not accept any parameters
Step-by-Step Solution
Solution:
  1. Step 1: Understand string immutability in JavaScript

    Strings are immutable, so value.trim() returns a new string but does not change original.
  2. Step 2: Check return statement

    The code returns original value without the trimmed result, so trimming has no effect.
  3. Final Answer:

    The trim() result is not returned, original value unchanged -> Option B
  4. Quick Check:

    Always return the result of string methods like trim() [OK]
Quick Trick: Return the result of string methods, don't ignore them [OK]
Common Mistakes:
  • Not returning trimmed string
  • Omitting parameters incorrectly
  • Missing @Injectable() decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes