typeof

A keyword that asks for the type of a value, both in JavaScript at run time and in TypeScript types.

In more detail

In JavaScript, typeof x returns a string such as "number". In a TypeScript type position, typeof router means “the type of this value”, which is how export type AppRouter = typeof router shares a server’s shape without sharing its code.

Examples

if (typeof param === "number") return param.toFixed(0);
type Environment = typeof API_CONFIG["environment"];

Related terms

Taught in

References