const assertion (as const)

Asserts the most specific literal, readonly type for an expression.

Since TS 3.4 Spec ↗

Syntax

expression as const

Examples

const point = { x: 1, y: 2 } as const;
// type: { readonly x: 1; readonly y: 2 }
const roles = ['admin', 'user'] as const;
type Role = typeof roles[number]; // 'admin' | 'user'

Notes

A const assertion narrows literals to their exact value, makes object properties and arrays `readonly`, and turns arrays into readonly tuples. It is ideal for deriving union types from arrays and for immutable config. Also available as a `const` type parameter modifier since TS 5.0.

See also