← All notes

as const keeps literal types from widening

Answer: Use as const to convert an entire object to type literals. Properties are assigned the literal type, not a more general version like string or number.

What as const changes

If you initialize a variable with an object, TypeScript assumes those properties might change later. An as const assertion on the object turns its values into type literals.

Const assertions also stop literal widening in general, give object literals readonly properties, and turn array literals into readonly tuples.

Limits

A const assertion applies only to a string, number, boolean, array, or object literal. Const contexts don't immediately convert an expression to be fully immutable.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Microsoft (TypeScript Handbook), Everyday Types (Literal Inference), CC-BY-4.0 (https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE); microsoft/TypeScript-Website (GitHub), TypeScript 3.4 release notes (const assertions), CC-BY-4.0 (https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft (TypeScript Handbook), Everyday Types (Literal Inference), CC-BY-4.0 (https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE); microsoft/TypeScript-Website (GitHub), TypeScript 3.4 release notes (const assertions), CC-BY-4.0 (https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE).

Cite this

Permanent ID: iil:note:zmb6mzmg

iinventedlight. 2026. "as const keeps literal types from widening." iinventedlight Library, iil:note:zmb6mzmg, version of 2026-11-17. https://iinventedlight.com/library/notes/typescript-const-assertions/. License: CC-BY-4.0.

@misc{iil_note_zmb6mzmg,
  author = {{iinventedlight}},
  title = {{as const keeps literal types from widening}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-17},
  url = {https://iinventedlight.com/library/notes/typescript-const-assertions/},
  note = {Permanent ID iil:note:zmb6mzmg. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/typescript-const-assertions.md.