TypeScript keyof and typeof type operators
Short answer
keyof T gives a union of the property keys of T. typeof x, used in a type position, gives the type of a variable. Together they derive types from existing code instead of repeating it. [S1][S2]
Example
type Point = { x: number; y: number };
type P = keyof Point; // "x" | "y"
const cfg = { port: 80, host: "a" };
type Cfg = typeof cfg; // { port: number; host: string }
type Key = keyof typeof cfg; // "port" | "host"
ReturnType<typeof fn> is a common pattern: pass a function's type, not its name. [S2]
Claims
- id: C1 claim: keyof produces a union of an object type's keys. source: S1 evidence: "produces a string or numeric literal union of its keys"
- id: C2 claim: keyof is especially useful with mapped types. source: S1 evidence: "especially useful when combined with mapped types"
- id: C3 claim: typeof can be used in a type context. source: S2 evidence: "in a type context to refer to the type of a variable or property"
- id: C4 claim: ReturnType takes a function type and yields its return type. source: S2 evidence: "It takes a function type and produces its return type"
Sources
- [S1] TypeScript: Documentation - Keyof Type Operator. Microsoft (TypeScript Handbook). https://www.typescriptlang.org/docs/handbook/2/keyof-types.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-04.
- [S2] TypeScript: Documentation - Typeof Type Operator. Microsoft (TypeScript Handbook). https://www.typescriptlang.org/docs/handbook/2/typeof-types.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft (TypeScript Handbook), TypeScript: Documentation - Keyof Type Operator, CC BY 4.0 (microsoft/TypeScript-Website); Microsoft (TypeScript Handbook), TypeScript: Documentation - Typeof Type Operator, CC BY 4.0 (microsoft/TypeScript-Website).
Cite this
iinventedlight. 2026. "TypeScript keyof and typeof type operators." iinventedlight Library, iil:note:2nvk9fbp, version of 2026-11-04. https://iinventedlight.com/library/notes/typescript-keyof-typeof/. License: CC-BY-4.0.
@misc{iil_note_2nvk9fbp,
author = {{iinventedlight}},
title = {{TypeScript keyof and typeof type operators}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/typescript-keyof-typeof/},
note = {Permanent ID iil:note:2nvk9fbp. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/typescript-keyof-typeof.md.