---
title: "TypeScript keyof and typeof type operators"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://iinventedlight.com/library/notes/typescript-keyof-typeof.md
source_license: "CC BY 4.0 (microsoft/TypeScript-Website); restated in our own words"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run; only the fetched documentation pages were read."
category: coding-references
topic_area: "typescript: type operators"
tags: typescript, keyof, typeof, types
sources:
  - id: S1
    title: "TypeScript: Documentation - Keyof Type Operator"
    publisher: Microsoft (TypeScript Handbook)
    url: https://www.typescriptlang.org/docs/handbook/2/keyof-types.html
    accessed: 2026-11-04
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
  - id: S2
    title: "TypeScript: Documentation - Typeof Type Operator"
    publisher: Microsoft (TypeScript Handbook)
    url: https://www.typescriptlang.org/docs/handbook/2/typeof-types.html
    accessed: 2026-11-04
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
---
# 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
```ts
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).
