as const
Last updated
What is as const?
as const is a TypeScript feature that allows you to tell the compiler to infer the narrowest or most specific type possible for an expression. Instead of the compiler widening the type of a value to its general type (like inferring a string variable as string), as const makes the compiler infer the value as a constant type (like inferring a string variable as the specific string literal type "hello"). This is useful for creating immutable data structures or when you need the compiler to enforce the exact values allowed.
Free resources to learn as const
- Official docsconst assertions
More in stage 5: Combining Types
as const: common questions
Can I learn as const in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain as const in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this as const tutorial for beginners?
It is lesson 29 of 93 in the free TypeScript roadmap, in stage 5, Combining Types. If you are new to TypeScript, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.