0Pricing
TypeScript Academy · Lesson

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

  1. Generic functions & constraints (extends, default params)
  2. Partial, Readonly, Record, Pick, Omit
  3. keyof/indexed access types (intro)
← Back to TypeScript Academy