TypeScriptInterview preparation
Intermediate·Concept·2 min read

What are mapped types, conditional types and decorators?

Practice this question

Definition:

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.

Key points:

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

Interview point:

  • 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?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.