0Pricing
TypeScript Academy · Lesson

The typeof Type Operator

Capture the type of a runtime value with typeof.

Types From Values

The typeof type operator derives a static type from a runtime value. It lets you write a value once and reuse its shape as a type, keeping the two in perfect sync.

Two Different typeofs

Do not confuse them: JavaScript's typeof returns a string at runtime; TypeScript's typeof appears in a type position and produces a type. Same keyword, different worlds.

const n = 42
console.log(typeof n) // "number" — JS runtime
type T = typeof n     // number — TS type position

All lessons in this course

  1. The typeof Type Operator
  2. The keyof Type Operator
  3. Indexed Access Types
  4. Combining typeof and keyof
← Back to TypeScript Academy