0Pricing
TypeScript Academy · Lesson

Mapped Types: Transforming Object Types

Loop over keys to create new type shapes.

Welcome

Mapped types iterate over the keys of a type to create new types with transformed properties. They are the foundation of Partial, Readonly, Record, and many other utilities.

Basic Mapped Type Syntax

Use `[K in keyof T]` to iterate over all keys of T and produce a new type.
type Copy<T> = { [K in keyof T]: T[K] };
type UserCopy = Copy<User>; // same as User

All lessons in this course

  1. Mapped Types: Transforming Object Types
  2. Modifiers in Mapped Types: readonly and ?
  3. Template Literal Types: String Patterns
  4. Key Remapping with as in Mapped Types
← Back to TypeScript Academy