There are situations where one would like to cover all possible values of a variable using conditional cases. A good example of this situation is a typical reducer function. Let’s consider an example of a counter with simple actions:
type Action = 'increment' | 'decrement';
So far so good. Now, let’s see what happens when another kind of action is added –
'reset', which in effect should set the counter back to 0.
type Action = 'increment' | 'decrement' | 'reset';
Now, let’s assume that you forgot to update the
reducer function. Considered example is overly simplistic, but maybe the codebase is large and you didn’t even know about the existance
reducer at all.