-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Promise.catch should have a return type of <TResult>, not T. #3834
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
Comments
That said the promise definition is best effort and not designed to be 100% correct, but the change you are recommending is not one that should be done 🌹 |
On second reading your suggestion isn't bad and maybe worth doing. I just wanted to point out that it is still best effort. |
@rbuckton might have something to say here |
I'm actually not entirely sure what happens if you chain a promise to a catch that doesn't return. Does the original promise result get chained through? Does the chain get stopped prematurely? Example: promise.catch(error => {
// intentionally does not return, is this considered a programming error?
}).catch(error => {
console.log(error); // what does this do?
}); I believe the answer to this question would shed some light on what the signature should look like. |
Here is a concrete example with comments to show what will happen: Promise.reject(new Error('I want to get caught')).catch(error => {
// I have caught the error and swallowed it silently
}).catch(error => {
// This never gets called as the error has been caught by the previous catch
}).then(foo=>{
// foo is the return of the first `catch` and therefore `void`
});
Basically a true implementation starts to feel like JAVAs throws : http://stackoverflow.com/a/29287864/390330 |
There doesn't seem to be much demand for this, and without sample code it's hard to evaluate what the deficit is. |
Current implementaiton:
What I believe is a more correct implementation:
I believe the spec says that
catch(x)
behaves the same asthen(undefined, x)
, which implies that catch should be a generic method with aTResult
type.If I am misunderstanding the spec, enlightenment would be appreciated.
The text was updated successfully, but these errors were encountered: