TypeScript for Application Developers
LESSON 1.3

Literal types and const assertions

Learn key techniques and workflows in TypeScript for Application Developers.

5m
intermediate
19,825 students

Overview

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

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

Pro Tip

Use caching and revalidation wisely to ensure your app stays fast and data remains fresh without unnecessary requests.

Resources