Introduction
This is the most important chapter of this course. It will teach you how to create new types from existing types.
First, we look at the most basic way of composing types with union and intersection operations. Union types are ubiquitous in TypeScript so it’s important to thoroughly understand them.
Second, we introduce the topic of discriminated unions. It’s a powerful mechanism that can be used to express business rules in the type system. Next, we’ll talk about state machines, a very useful state management technique that can be implemented using discriminated unions. Finally, we’ll compare discriminated unions and subtyping to see when to use which technique.
Get hands-on with 1200+ tech skills courses.