-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript 2.1+ and Errors #2612
Comments
So we're not considering mutating Error construction to make custom error object backward compatible like proposed at #2582 (comment) ? |
FWIW: The Angular team has also gone with the approach I mentioned above. I think it's clean and simple. Sucks that it's breaking, but I think it's time we consider releasing a v6 beta. |
@kwonoj ...given that no one's compiler is supporting this, and you'll end up needing to hack around it in ES5 anyhow, we should probably jump on a simple but familiar solution. |
I see. Let's see if there's some other opinion as well. /cc @david-driscoll too. |
I think it makes sense. We could introduce an interface as well if we need to be able to capture additional information. Something like... const timeoutErrorMsg = 'RxJS Timeout Error';
const timeoutErrorSymbol = Symbol(timeoutErrorMsg);
export interface TimeoutError extends Error { hello: string; }
export function createTimeoutError(): TimeoutError {
const error = new Error(timeoutErrorMsg);
error[timeoutErrorSymbol] = true;
return <any>error;
}
export function isTimeoutError(err: Error): err is TimeoutError {
return err && err[timeoutErrorSymbol];
} |
A symbol sounds unnecessarily complex for this. Every other Error in NodeJS just has a Another option is to transpile TypeScript's ES6 output with Babel, which gets the inheritance right. That said, error codes are always a better idea, because any check should work no matter from what version of rxjs the error came from, which is not true for |
We're well past this now. |
Issue
Currently, we're extending
Error
to create the ability to doinstanceof
checks again things likeObjectUnsubscribedError
. This is no longer something that TypeScript supports for a variety of principled reasons.Proposed Change
We move to just throwing simple
new Error()
, but decorating that error with a custom property, and providing a method to check that property. Ideally, that property will be set with aSymbol
to avoid collisions.And then to check an error:
Other Things
We should probably make these utilties available on
Rx.Util
. for example:Rx.Util.isTimeoutError
This affects the following
EmptyError
TimeoutError
ArgumentOutOfRangeError
UnsubscriptionError
ObjectUnsubscribedError
This would be a BREAKING CHANGE for sure.
The text was updated successfully, but these errors were encountered: