Mapped Types

A mapped type is derived from an existing type by modifying the properties’ names or accessibility (e.g. readonly) in the new type.

Example:

1
2
3
4
5
6
7
8
9
10
11
// Existing Type
type User = {
age: number;
firstName: string;
lastName: string;
}

// Mapped Type
type PartialUser = {
[P in keyof User]?: User[P];
};

More about mapped types ➝