TypeScript - Type Manipulation: keyof, Indexed & Mapped Types

keyof and indexed access

type User = { id: string; name: string; age: number };

type UserKey = keyof User;      // 'id' | 'name' | 'age'
type UserName = User['name'];   // string

Mapped types

type Readonly = { readonly [K in keyof T]: T[K] };

type Partial = { [K in keyof T]?: T[K] };

Remapping keys

type PrefixKeys = {
  [K in keyof T as `${P}${Extract}`]: T[K]
};