A string literal type represents an exact value (e.g. 'idle') instead of any string. A union of literals models a small, fixed set that callers must choose from. Narrowing with a switch helps you return different results for each case while keeping the function’s return type consistent.
type Traffic = "red" | "yellow" | "green";
let t: Traffic = "red";Use literal unions for app states and user-visible modes you want the type system to enforce. Prefer a switch when you have several distinct branches and want readability.
type Status = 'idle' | 'loading' | 'success' | 'error'.describeStatus(status: Status): string that returns exactly:'Idle' for 'idle''Loading...' for 'loading''Success' for 'success''Error' for 'error'.