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 positionAll lessons in this course
- The typeof Type Operator
- The keyof Type Operator
- Indexed Access Types
- Combining typeof and keyof