Skip to content
dreamcode
dreamcode
Map
Mapped
Lesson 22 of 26
+15 XP on finish
TYPESCRIPTChapter 4 · TS Expert

Mapped Types

Mapped Types build new types by iterating over the keys of an existing type. They map every property of a type to a new type structure, similar to Array.prototype.map() but for type properties.

Worked example

How it reads

  • [K in keyof T] iterates over all keys K inside type T
  • T[K] accesses the type of property K in type T
Cloud tip: Mapped types are useful for converting API responses or validation payloads dynamically.
index.ts
TYPESCRIPT
type-checked, then run in your browser
Console
Run your code to see its output here.
YOUR TURN

Write a mapped type Flags<T> that turns every property into a boolean, then const shown: Flags<Pilot> = { name: true, xp: false } and log shown.xp: false.

Press Run to check your work.