What is a discriminated union in TypeScript?

TypeScript Associate Medium

TypeScript Associate — Medium

What is a discriminated union in TypeScript?

Key points

  • Discriminated unions use a shared literal property for type distinction
  • This allows for exhaustive type narrowing in TypeScript
  • Each type in the union must have the common property
  • Helps in writing more robust and type-safe code

Ready to go further?

Related questions