How does the 'Const Assertion' (as const) affect inference?

Updated May 4, 2026

Short answer

'as const' signals the compiler to infer the most specific literal types possible and makes all properties 'readonly'.

Deep explanation

Usually, TypeScript 'widens' literal types (e.g., 'hello' becomes string). When you use as const, widening is disabled. Objects get readonly properties, arrays become readonly tuples, and primitive types are treated as their literal values. This is incredibly useful for configuration objects or ensuring that a set of values remains immutable and precisely typed.

Real-world example

Defining a fixed set of action types in a Redux-like pattern to ensure the dispatcher only receives valid strings.

Common mistakes

  • Using `as const` on a variable that you actually intend to mutate later in the code.

Follow-up questions

  • How does 'as const' differ from Object.freeze()?

More TypeScript interview questions

View all →