keyof/indexed access types (intro)
Use keyof to create unions of property names and indexed access types (T[K] / T["prop"]) to read property types safely.
Intro
Goal: Build safer helpers using keyof (property-name unions) and indexed access (T[K]) to read property types.
keyof
keyof produces a union of property names of a type (e.g., "id" | "name" | "email").
interface User {
id: number;
name: string;
email?: string;
}
type UserKeys = keyof User; // "id" | "name" | "email"All lessons in this course
- Generic functions & constraints (extends, default params)
- Partial, Readonly, Record, Pick, Omit
- keyof/indexed access types (intro)