TypeScript tutorialLesson 12Free preview
TS Union Types
This lesson is part of TypeScript · All levels
Summary
Union type combines several types with pipe markings so a value can be one of them. Before using a special property, the type must be narrowed down through a check. Discriminated unions help distinguish data variants through marker properties such as kind or type.
Key points
- Union is written with a pipe mark.
- Mandatory narrowing before access to special property
- Discriminated unions use marker property
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.