Five TypeScript habits that saved me hours
None of these are clever. They are just habits.
1. Prefer unions to enums
type Status = 'idle' | 'loading' | 'error';
2. Narrow early
Return early on the bad cases so the rest of the function deals with one clean shape.
3. Let inference work
Annotate function boundaries, not every variable.
4. Parse, donβt validate
Turn unknown input into a typed value once, at the edge.
5. Make illegal states unrepresentable
If two fields can never both be set, model that in the type.