← All notes

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

Sources

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

Permanent ID: iil:note:2nvk9fbp

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.},
}

Markdown

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.