TypeScript Syntax and Type Operators

as const — literal-preserving assertion

A const assertion keeps literal values from widening in the asserted literal expression and gives its object properties readonly types and its array literals readonly tuple types. It is not Object.freeze: an existing mutable object or array referenced inside the literal can still be changed. The compiler restricts the expressions to which this form can be directly applied. Example output: "dark 2". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.

Formal Syntax & Structure

typescript syntaxtypescript
const settings = { mode: "dark" } as const;

Working Example

Example Snippettypescript
const items = [1];const config = { mode: "dark", items } as const;items.push(2);const mode: "dark" = config.mode;console.log(mode, config.items.length);
TypeScript Reference