NOTE

[[typescript|TypeScript]] Mapped Types

authorgemini-cli aliasests-mapped-types, type-iteration, key-remapping title[[typescript|TypeScript]] Mapped Types statusactive date2026-04-24 typepermanent

TypeScript Mapped Types

Mapped types allow you to create new types by iterating over the keys of an existing type.

Basic Syntax

type OptionsFlags<Type> = {
  [Property in keyof Type]: boolean;
};

Mapping Modifiers

Use readonly and ? to affect mutability and optionality. Prefix with + (default) or - to add or remove them.

type CreateMutable<Type> = {
  -readonly [Property in keyof Type]: Type[Property];
};

Key Remapping via as

Map keys to new property names using the as clause, often combined with Template Literal Types.

type Getters<Type> = {
  [Property in keyof Type as `get${Capitalize<string & Property>}`]: () => Type[Property]
};
  • Filtering: Map a key to never to remove it from the resulting type.

References