https://github.com/buschtoens/unsupported-value-error
Utility Error class for performing exhaustiveness checks via exceptions in TypeScript.
https://github.com/buschtoens/unsupported-value-error
control-flow exhaustiveness-checking types typescript
Last synced: 6 months ago
JSON representation
Utility Error class for performing exhaustiveness checks via exceptions in TypeScript.
- Host: GitHub
- URL: https://github.com/buschtoens/unsupported-value-error
- Owner: buschtoens
- License: isc
- Created: 2020-04-07T10:51:21.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T02:26:11.000Z (over 2 years ago)
- Last Synced: 2024-10-09T12:43:07.728Z (over 1 year ago)
- Topics: control-flow, exhaustiveness-checking, types, typescript
- Language: TypeScript
- Size: 79.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unsupported-value-error
[](https://github.com/buschtoens/unsupported-value-error/actions)
[](http://badge.fury.io/js/unsupported-value-error)
[](http://badge.fury.io/js/unsupported-value-error)
[](https://github.com/prettier/prettier)
[](https://dependabot.com/)
[](https://david-dm.org/buschtoens/unsupported-value-error)
[](https://david-dm.org/buschtoens/unsupported-value-error?type=dev)
Little TypeScript utility Error class for performing exhaustiveness checks via
exceptions, based on [this post by Dr. Axel Rauschmayer][blog-post].
[blog-post]: https://2ality.com/2020/02/typescript-exhaustiveness-checks-via-exceptions.html
```ts
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'
}
}
```