neverthrow
neverthrow copied to clipboard
Ensure that `createNeverThrowError` returns an Error that is an instance of `Error` class.
Internally at Google, we have some company-wide conformance tests that ensure that all errors that are thrown, are subclasses of Error.
To ensure this, I adjusted the createNeverThrowError func to return a new NeverThrowError class, which both extends Error and overwrites the object's prototype to ensure that it is Error.
This allows for:
createNeverThrowError(...) instanceOf Error
> true
createNeverThrowError feels like an internal detail of the library and is only used in some fringe boundary cases. I added a quick test in a spot that felt the most obvious. Suggestions on alternatives are welcome!