Lesson 1.36mIntermediate19.8k students

Literal types and const assertions

Widening is why your string turned into string. A const assertion keeps the literal, which is what makes union-of-literals modelling work.

This lesson sits in How the Type System Thinks, part of TypeScript for Application Developers. It assumes what came before it and leads directly into the next lesson in the module.

In this lesson you will

  • Understand literal widening and when it happens
  • Freeze a literal shape with as const
  • Derive a union of allowed values from a constant array

Resources