mapped type
A type that builds a new object type by looping over a set of keys, such as { [K in keyof T]: T[K] }.
In more detail
Partial, Readonly and Record are mapped types. They can add or remove the readonly and optional modifiers, and with an as clause rename or drop keys.
Related terms
- key remapping — Renaming or filtering keys inside a mapped type with an as clause, such as [K in keyof T as `get${Capitalize<K & string>}`].
- mapping modifier — A plus or minus sign before readonly or the optional question mark in a mapped type, which adds or removes that modifier from every property.
- keyof — The TypeScript type operator that produces a union of an object type's property names, such as "id" | "table" | "rowCount".
- utility types — Generic types built into TypeScript, such as Partial, Pick and ReturnType, that compute a new type from an existing one.
Taught in
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Conditional Types: Ternary Types And Type Inference With infer — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript