"You wrote a value. Now you have its type, for free."
The type-level typeof
In a type position, typeof someValue evaluates to the type of someValue. const u = { id: 1, name: 'Pippa' }; type U = typeof u — U is { id: number; name: string }. The compiler reads the value's inferred type and gives you a type with that shape.
This is distinct from the runtime typeof operator (which returns a string at runtime). The type-level version exists only in type positions and is one of TypeScript's most useful features for keeping types in sync with values.
When to reach for it
Constants → types. If you have a constant and want to express the same shape as a type, typeof constant does it without retyping. const ROUTES = { CHAT: '/chat' } as const; type Routes = typeof ROUTES.
Functions → signatures. Combined with ReturnType and Parameters, you can extract a function's pieces without naming them. type Result = ReturnType<typeof fetchUser>.
External libraries. If a library exports a value but not a type for it, typeof exportedValue recovers the type.
typeof is how you make the value the source of truth and the type a derived view. The value is what runs; the type is what the compiler checks. Both come from one declaration.