Skip to content

Mapped Type

In one line

A mapped type is a TypeScript construct that iterates over the properties of an existing type and produces a new type with transformed properties.

In simple words

A mapped type iterates over the keys of an existing type and transforms each property. The syntax is { [K in keyof T]: NewType }. It is the foundation of all utility types like Partial, Readonly, and Pick.

For example, type Stringify<T> = { [K in keyof T]: string } takes any type T and creates a new type with the same keys but all values as strings.

Mapped types are powerful for creating type transformations: making properties optional, readonly, or changing their types. The built-in utility types (Partial, Required, Readonly, Pick, Omit) are all mapped types.

Example

typescript
type Mutable<T> = { -readonly [K in keyof T]: T[K] };
type Getters<T> = { [K in keyof T]: () => T[K] };

Mutable removes readonly modifiers. Getters creates getter functions for each property.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary