TypeScript Syntax and Type Operators
keyof — permitted property key type
The keyof operator computes a type of permitted property names, not a runtime array. Explicit members can produce string, numeric or unique-symbol literal keys. A string index signature gives string | number because numeric property access can be converted to a string key. For a union, only keys accessible on every constituent are guaranteed. Object.keys() is not generally typed as a list of keyof values. Example output: "ready". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.
Formal Syntax & Structure
typescript syntaxtypescript
type Keys = keyof { id: number; label: string };Working Example
Example Snippettypescript
type Ticket = { id: number; label: string };const key: keyof Ticket = "label";const ticket: Ticket = { id: 1, label: "ready" };console.log(ticket[key]);