Mapped Types Introduction

This lesson introduces the concept of mapped types.

Overview

Mapped types are another way to transform types. In simple words, they let you take an object type (an interface) and return a new type with each property transformed in some way.

Mapped type example - Readonly type

The best example for understanding mapped types is the built-in Readonly type. As you can see, Readonly is a generic type. It takes an object type T, enumerates its properties (P in keyof T), and adds the readonly modifier to each property. You can think of mapped types as an equivalent of the for..of loop in the world of types.

Get hands-on with 1200+ tech skills courses.