LESSON 06 / 6·2 min readIntermediate

What are mapped types, conditional types and decorators?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand 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.

PAUSE & RECALL

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.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Separate compile-time tools from runtime mechanisms, even when both appear in TypeScript source.
Practice this concept
YOUR NEXT STEP

You’ve reached the end of this guide.

Prepare for TypeScript interviews

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.