7.6 Combining Literals with Union Types for Discriminated Unions
Now we get to the good stuff. You’ve seen literal types and union types on their own, but when you combine them, you unlock one of TypeScript’s most powerful patterns: the discriminated union. The name sounds fancy, but the concept is beautifully simple. It’s how we tell TypeScript, “Look, this object could be one of several shapes, and here’s the literal value you can check to know exactly which one it is.”