Bird
0
0

Why is it important to use the Reflector class instead of directly using Reflect.getMetadata in NestJS guards?

hard📝 Conceptual Q10 of 15
NestJS - Guards
Why is it important to use the Reflector class instead of directly using Reflect.getMetadata in NestJS guards?
ABecause Reflect.getMetadata is deprecated in NestJS
BBecause Reflect.getMetadata only works on classes, not methods
CBecause Reflector automatically sets metadata for you
DBecause Reflector abstracts metadata retrieval and handles inheritance and context properly
Step-by-Step Solution
Solution:
  1. Step 1: Understand Reflector advantages

    Reflector provides a convenient API that respects inheritance and merges metadata from class and method contexts.
  2. Step 2: Clarify misconceptions

    Reflect.getMetadata is not deprecated, Reflector does not set metadata, and Reflect.getMetadata works on both classes and methods.
  3. Final Answer:

    Because Reflector abstracts metadata retrieval and handles inheritance and context properly -> Option D
  4. Quick Check:

    Reflector manages metadata context and inheritance = B [OK]
Quick Trick: Reflector handles inheritance and context better than Reflect.getMetadata [OK]
Common Mistakes:
  • Thinking Reflect.getMetadata is deprecated
  • Assuming Reflector sets metadata
  • Believing Reflect.getMetadata only works on classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes