Lesson 1.3

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.

Taught byDaniel OkaforTypeScript · PostgreSQL · API design · Data modelling
6m 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.

What this lesson covers

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

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