Question · JavaScript and TypeScript course · Module 7: Advanced TypeScript

Discriminated Union

What is a discriminated union in TypeScript?

Answer options

  • A union of types where each variant has a common field (tag) with a unique literal value
  • A type that discriminates (rejects) null and undefined values
  • A special generic type for filtering unions
  • An inheritance mechanism allowing polymorphism

You can check the correct answer by solving this task in the CodeWorlds game.