make illegal states unrepresentable
phrase
- Designing data types so invalid combinations cannot even be constructed, eliminating a whole class of bugs. Replace isLoading, isError and data with one union: Loading | Error(message) | Loaded(data).
In plain words
- impossible combinations of flags
- loading and error are both true at once
- bugs from invalid states
- booleans that contradict each other
See also finite state machine parse, don't validate invariant