TypeScript 7 reference · Type Operators and Keywords

TypeScript Type[Key] Operator

Look up the type of a property with Type['key'], or of array elements with Type[number].

TypeScript 7 Since 2.1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Type[Key]

Examples

A nested property's typeTry it yourself
interface Order {
  id: number;
  customer: { name: string; email: string };
}
type Customer = Order["customer"];
const c: Customer = { name: "Ana", email: "[email protected]" };
console.log(c.name);

Output

Ana
Element type of an arrayTry it yourself
const sizes = ["S", "M", "L"] as const;
type Size = (typeof sizes)[number];
const s: Size = "M";
console.log(s);

Output

M

Version history

VersionChange
TypeScript 2.1Added

Was this page helpful?