Skip to content

Mapped Types

A mapped type is a type that transforms one type into another type by iterating over its properties.

Syntax

type NewType = {
    [Property in keyof OriginalType]: NewPropertyType 
}

Example: Make all properties readonly

interface Todo {
  title: string;
  completed: boolean;
}

type ReadonlyTodo = {
  readonly [Property in keyof Todo]: Todo[Property];
}

References