Mapped Types
Learn about TypeScript's generic syntax, the keyof keyword, and predefined mapped types (Partial, Required, Readonly, Pick, and Record) for creating new types based on existing ones.
Introduction to mapped types
We can use a type alias to define a special named type. Type aliases, however, can become even more powerful when combined with generic syntax, allowing us to create types based on other types.
Add in the keyof
keyword, and we can create new types based on the properties of another type.
This is best illustrated with an example as follows:
Get hands-on with 1400+ tech skills courses.