Union types let a value be one of several possibilities, while literal types restrict values to exact constants:
type Status = 'idle' | 'loading' | 'success' | 'error';
type Id = string | number;
let status: Status = 'loading'; // ✅ OK
let status: Status = 'pending'; // ❌ ErrorTypeScript performs control-flow narrowing: inside branches guarded by typeof, equality checks, or switch, the compiler refines a union to a specific member, giving you type safety and better autocompletion.
In this category, you'll:
string | number)typeof, equality checks, and switchkind or type)This category focuses on practical everyday patterns: clear narrowing and small, well-defined state sets.