const type parameter

A type parameter marked const, such as <const T>, which makes the compiler infer the exact literal types of arguments, as if the caller wrote as const.

In more detail

Added in TypeScript 5.0, it lets defineRoutes([...]) keep "/health" and "GET" instead of widening them to string. The inferred arrays become readonly tuples, so the constraint should also say readonly.

Example

function defineRoutes<const T extends readonly RouteSpec[]>(routes: T): T

Related terms

Taught in

References