Guided Notes
keyof, typeof, Indexed & Mapped Types
Getting keys with keyof, types from values with typeof, indexed access types, mapped types, template literal types, and conditional types in practice.
keyof and typeof
Slide 1 / 4keyof produces a union of an object type's keys: interface Car { make: string; year: number } type CarKey = keyof Car; // "make" | "year"
typeof (in a type position) gets the type of a value: const defaults = { theme: "light", pageSize: 20 }; type Defaults = typeof defaults; // { theme: string; pageSize: number }
Combined: keyof typeof defaults is "theme" | "pageSize".
