Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Utility Types

TypeScript PropertyKey type

Reference for PropertyKey in TypeScript: the built-in union string | number | symbol, how it relates to keyof any, Reflect, and generic key parameters.

PropertyKey is a built-in type alias for string | number | symbol: every type that can be used as a property key in JavaScript. It is what keyof of an object with an unknown shape resolves to, and what many standard APIs (Reflect.get, Object.defineProperty, Object.hasOwn) accept as a key.

Use it when you write generic helpers that handle keys without knowing whether they are strings, numbers or symbols, and as a constraint for "any key" type parameters.

TypeScript
type PropertyKey = string | number | symbol;

Try it

TypeScript A helper that accepts any key kind

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript PropertyKey versus keyof any

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

TypeScript
declare type PropertyKey = string | number | symbol;

It is declared in the core library (lib.es5.d.ts) and is always available. There are no parameters; the table below lists the three members.

Member Description
string Ordinary names, including numeric-looking ones ("1").
number Array-style indices; at runtime they are converted to strings.
symbol Unique keys such as Symbol.iterator or ones you create with Symbol().

Edge cases:

  • keyof any is string | number | symbol, the same set. keyof {} is never, and keyof object is never as well.
  • Since TypeScript 2.9, keyof T can include number and symbol, so code that assumed string keys needs keyof T & string or Extract<keyof T, string>.
  • The old keyofStringsOnly compiler option, which made keyof return only string, is deprecated and no longer supported by current compilers.
  • bigint is not a property key; a bigint used as a key is converted to a string at runtime.

Usage notes

  • Constrain generic keys with K extends PropertyKey when you build a Record<K, V>: Record's own key constraint is keyof any, so the two line up.
  • Narrow with typeof key === "symbol" when you need to treat symbols separately, for example before String(key) (concatenating a symbol throws).
  • Object literals with computed keys accept any PropertyKey, but index signatures only allow string, number, symbol and template-literal patterns, not unions of them.
  • JavaScript turns numbers into strings, so obj[1] and obj["1"] read the same slot.
  • It describes keys, not values. For the keys of one specific type use keyof T.