Course contentsShow
← TypeScript
Lesson 717 of 1,79617. Mapped TypesFree lesson

What Are Mapped Types?

Understanding mapped types as a way to transform existing types by iterating over their properties.

What Are Mapped Types?

You'll learn: How to programmatically transform object types by iterating over their properties, rather than manually rewriting each one.

The Core Idea

A mapped type is TypeScript's way of creating a new type by transforming each property in an existing type. Think of it like using Array.map() on values — but instead of transforming an array's values, you're transforming a type's properties at the type level.

You've already used mapped types without knowing it: utilities like Partial<T>, Readonly<T>, and Pick<T, K> are all implemented with mapped types under the hood.

How It Works Conceptually

Instead of writing this manually:

// Before: manually rewriting properties
type User = { name: string; age: number; email: string };
type OptionalUser = { name?: string; age?: number; email?: string };

Mapped types let you express "make all properties optional" as a transformation rule:

// After: automated transformation
type MakeOptional<T> = {
  [K in keyof T]?: T[K];
};

type OptionalUser = MakeOptional<User>;
// Result: { name?: string; age?: number; email?: string }

The syntax [K in keyof T] means: "for each key K in the keys of T, create a property with that key."

Why This Matters

Mapped types eliminate repetition when you need to apply the same modification to all properties. They're foundational for creating reusable type utilities and keeping your types DRY (Don't Repeat Yourself).

Key Takeaway: Mapped types iterate over an existing type's properties to create a new, transformed type — they're the type system's version of iteration and transformation.