Skip to content
skillbld
Day 5 of 14 30 minUnionsLiteral typesDiscriminated unions

Model values that can be one of several types. Write unions of types and of literal values, see what you can do with a union before checking it, and model different kinds of data with discriminated unions.

By the end of today you can

  • Write union types with the | operator
  • Use literal unions to allow only specific values
  • Explain which operations are allowed on a union before narrowing
  • Model alternatives with discriminated unions
  • Replace bags of optional properties with clearer unions

What's inside

  • 4 sections
  • 2 diagrams and mind maps
  • 6 code examples you can run
  • 5-question quiz
  1. 1Unions of types
  2. 2Literal unions: an exact list of values
  3. 3Discriminated unions
  4. 4Modelling: make impossible states impossible

Sign in free to read this lesson

Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.

Sign in free
Day 5: Union Types · TypeScript · SkillBld