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.

5mIntermediate19,825 students
Video thumbnail for Literal types and const assertions

Sign in to watch this lesson

Browsing is free. Create an account to play videos and track your progress.

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
Literal types and const assertions — Skiply