An indexed access type T[K] looks up the type of a property with the bracket syntax you use to read a value. The index can be a literal, a union of keys, keyof T (giving the union of all value types), or number to get an array's element type. It reaches into large generated types, such as API client responses, without copying nested shapes:
type Order = {
id: string;
customer: { name: string; address: { city: string; zip: string } };
items: { sku: string; price: number }[];
};
type Address = Order["customer"]["address"]; // { city: string; zip: string }
type LineItem = Order["items"][number]; // { sku: string; price: number }
const ROLES = ["admin", "editor", "viewer"] as const;
type Role = (typeof ROLES)[number]; // "admin" | "editor" | "viewer"
const line: LineItem = { sku: "A1", price: "9.99" };
const role: Role = "owner";Output
order.ts(10,37): error TS2322: Type 'string' is not assignable to type 'number'. order.ts(11,7): error TS2322: Type '"owner"' is not assignable to type '"admin" | "editor" | "viewer"'.
The ROLES pattern is worth memorizing: one runtime array feeds both a <select> menu and the Role type, so the two cannot drift apart.