Little TypeScript utility Error class for performing exhaustiveness checks via exceptions, based on this post by Dr. Axel Rauschmayer.
enum NoYes {
No = 'no',
Yes = 'yes'
}
function toGerman(x: NoYes) {
switch (x) {
case NoYes.No: return 'Nein';
// case NoYes.Yes: return 'Ja';
default: throw new UnsupportedValueError(x);
// => TS2345: Static TS error: Argument of type 'NoYes.Yes' is not assignable to parameter of type 'never'.
// => Runtime: Unsupported value: 'yes'
}
}