TypeScript Syntax and Type Operators

typeof — type query

A type query refers to the static type of a value identifier or qualified property name. It does not evaluate an arbitrary expression, unlike JavaScript typeof in an expression. It preserves the type already inferred or annotated, not necessarily a single runtime literal. It is useful for deriving contracts from existing values or functions without writing their types twice. Example output: "3000". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.

Formal Syntax & Structure

typescript syntaxtypescript
type Settings = typeof settings;

Working Example

Example Snippettypescript
const settings = { port: 8080, secure: true };type Settings = typeof settings;const local: Settings = { port: 3000, secure: false };console.log(local.port);
TypeScript Reference