What is the purpose of the `as const` assertion in TypeScript?

TypeScript Associate Easy

TypeScript Associate — Easy

What is the purpose of the `as const` assertion in TypeScript?

Key points

  • `as const` helps TypeScript narrow down the type of the value to its most specific literal type.
  • This assertion is useful for ensuring that variables are treated as constants with specific values.
  • It does not convert the value to a constant at runtime or make the variable immutable in JavaScript.

Ready to go further?

Related questions