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
Half my code uses an enum for status, the other half just compares plain strings against each other, and honestly I don't know anymore which one is right.
What you'll have at the end
A short comment in the code explaining why you picked union over enum this time
You need
A codebase with one fixed set of named values, like a status or a role, modeled inconsistently: an enum in some files, plain string comparisons in others, and at least one place where the value arrives from outside your code, such as an API or webhook payload, as a plain string.
Not covered
Migrating every enum in the codebase in one pass, or validating the rest of the webhook payload's shape. Only this one field's type is in scope.
Leans on
Force an exhaustive switch that breaks the build on a missed case
For enforcing the exhaustive-switch pattern everywhere a status gets branched on, since this recipe only wires it into one function.
Model an API response so success and failure can't be confused
For when the outside data isn't a single status string but a whole shape that can mean success or failure.
Checked 22 Aug 2026
Part of the TypeScript cookbook