What are mapped types, conditional types and decorators?
Try code in the playgroundUnderstand the concept
Mapped types build a new type by visiting the keys of another type, and conditional types choose a type based on a type relationship. Decorators are different: they run as part of JavaScript class definition and can add metadata or change behavior. Type transformations disappear during compilation, while decorator code can affect runtime behavior.
Important ideas
-
Mapped types change fields:
{ [K in keyof T]?: T[K] }. -
Conditional types choose a type:
T extends string ? A : B. -
Decorators can add metadata or change runtime behavior; NestJS uses them to describe classes and routes.
-
Use mapped types to change property modifiers or value types consistently.
-
Decorator behavior depends on the decorator system and compiler/framework configuration; do not assume every decorator style works with Nest metadata.
Can you explain it without the notes?
What are mapped types, conditional types and decorators?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Mapped types build a new type by visiting the keys of another type, and conditional types choose a type based on a type relationship. Decorators are different: they run as part of JavaScript class definition and can add metadata or change behavior. Type transformations disappear during compilation, while decorator code can affect runtime behavior.
Turn this concept into a clear answer.
- Separate compile-time tools from runtime mechanisms, even when both appear in TypeScript source.
Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “What are mapped types, conditional types and decorators?”. Examples are study fragments; framework behavior can depend on your version.