KITFORMA · EDITORIAL ANSWER
How do I make a TypeScript switch fail compilation when a new status is added?
KitForma editorial guide. Use a discriminated union and assign the remaining value to never in the default branch: const unreachable: never = state.
Step-by-step answer
const unreachable: never = state. Return or throw there. Adding a union variant then exposes unhandled branches. Verify by temporarily adding a status. Keep the discriminant literal; a broad string property cannot provide exhaustiveness.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.