make illegal states unrepresentable

A design rule: shape your types so that invalid combinations, such as loading and error at once, cannot even be written.

In more detail

A type with separate optional loading, error and data fields allows nonsense combinations. A discriminated union allows only the real states, so the compiler rejects the impossible ones.

Related terms

Taught in

References