as const

The TypeScript suffix as const, which tells the compiler to treat an object's values as fixed literal values rather than general types.

In more detail

An object marked as const keeps every literal exactly instead of widening it to string or number, and all its properties become readonly. It only affects types; use Object.freeze for immutability at run time.

Examples

export const tokens = { colorPrimary: "#2563eb" } as const; types colorPrimary as exactly "#2563eb", so editors autocomplete token names and reject misspelled ones.
all: ["users"] as const
const API_CONFIG = { retries: 3, environment: "production" } as const;

Related terms

Taught in

References