typeof
In a type position, derives a type from the type of a runtime value.
Syntax
typeof value Examples
const settings = { dark: true, level: 3 };
type Settings = typeof settings;
// { dark: boolean; level: number }
function makeApi() {
return { get() {}, post() {} };
}
type Api = ReturnType<typeof makeApi>;
Notes
The type-level `typeof` is distinct from the runtime `typeof` operator. It
captures the inferred type of a variable, function, or class value, often
combined with `keyof`, `ReturnType`, or `InstanceType`. Use `as const` first
to capture literal types.