-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Inferred promise return type is invalid when catch is not using a arrow function #19282
Comments
Here is a minimal repro: const f = () => {
throw Error();
}; // () => never
function g() {
throw Error();
} // () => void I do not believe this is specifically related to the declarations for
That is correct behavior as a function that always throws is assignable to a function that returns a value of any arbitrary type. It is not related to the use of .catch((error: Error) => {
throw error;
}) which is an incorrect annotation. It passes the typechecker because |
Duplicate of #16608. |
I see the underlying problem referenced in the duplicate issue. The issue i stated here however is not about the root cause its about having to deal with promises that have additional return type because of the error handler which creates a lot of work handling the void return in every Promise.then case. I dont care about the referenced root problem. The problem here is about Promises being not usable as they should if you use normal functions. Which limits you to use arrow functions for Promise.catch. And this for me is a bug. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.5.3
Code
Expected behavior:
Functions test1 and test2 behave as exspected
Actual behavior:
The function test3 however has the return type Promise<string | void> which is not correct as functionally it has the same behavior as test2. It would never return void. As such it is a bug.
Also strange is: If i set the return type of the error handler to be of type Error. It doesnt trigger an ts error (it never returns anything). And the inferred return type of test3 is then Promise<string | Error>. The promise will never return a Error.
The text was updated successfully, but these errors were encountered: