New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
Somebody added a new status value. One switch statement never got updated.
What you'll have at the end
A switch statement that fails to compile the moment a new case goes unhandled
You need
A switch statement already keyed on a string literal union or a discriminated union's tag field, with at least two cases written and a plain catch-all underneath them.
Not covered
Deciding whether the underlying values should be a string literal union or an enum, and validating a status that arrives from outside the type system before it ever reaches the switch.
Leans on
Narrow an unknown JSON value before you trust it
for a status that arrives from outside the type system, such as a parsed API response, and needs validating before it ever reaches a switch
Enum or string union: picking the safer one
for deciding whether the set of statuses should be a string union or an enum before writing the exhaustive switch over it
Model an API response so success and failure can't be confused
for the same never-typed guard applied to a success-or-failure result instead of a status value
Checked 22 Aug 2026
Part of the TypeScript cookbook