← Back to context

Comment by ngruhn

4 hours ago

Isn't that overkill? You can check exhaustiveness with a trivial little helper:

    function exhaustive(witness: never): never {
      return witness
    }

https://www.typescriptlang.org/play/?#code/FAFwngDgpgBAKgZQB...

In the example you don't even need the default clause and the helper (the error message without it is worse though).

you can just to

    default:
        matched satisfies never
        throw new Error(...)

You don't even need a function.