Search⌘ K

Mapped Types Introduction

Discover how to use mapped types in TypeScript to create new types by transforming properties of existing object types. Learn about the Readonly generic type for shallow immutability and explore how recursive mapped types enable deep immutability, enhancing type safety in your advanced TypeScript projects.

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 ...