Syntax
type Name = User["name"];
type Row = Rows[number];Examples
Looking Up Property Types: working example
Run this standalone example after compiling with TypeScript 5.4+ in strict mode, targeting ES2022. Expected result: The program prints 2 × Book.
type Order = { id: string; lines: { label: string; quantity: number }[] };
type Line = Order["lines"][number];
function summarize(line: Line): string {
return `${line.quantity} × ${line.label}`;
}
console.log(summarize({ label: "Book", quantity: 2 }));- Expected result: The program prints 2 × Book.
- Order["lines"] obtains the array type.
- The second lookup [number] obtains one line’s object shape without redeclaring it.
Best practices
- Derive component and helper parameter types from the authoritative model.
- Use typeof when starting from a value instead of an existing type alias.
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook