Unions and Literals
Learning TypeScript's Unions and Literals chapter covers union and literal types in TypeScript, along with how its type system can deduce more specific (narrower) types from how our code is structured:
- How union types represent values that could be one of two or more types
- Explicitly indicating union types with type annotations
- How type narrowing reduces the possible types of a value
- The difference between constvariables with literal types andletvariables with primitive types
- The "billion-dollar mistake" and how TypeScript handles strict null checking
- Using explicit | undefinedto represent values that might not exist
- Implicit | undefinedfor unassigned variables
- Using type aliases to save typing long type unions repeatedly