-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Recursive async function return type not inferred when await on the self call #55973
Comments
See also #53995 In the In the |
Hmm, I was about to expand the logic from #53995 to cover for this. I struggle to find the reason why this couldn't be done here. Would you be able to illustrate what you mean by the nonzero effect on the |
I guess the thing that I have to be convinced of is that I'd want to see testcases like this declare const ps: Promise<string> | number;
async function foo1() {
if (Math.random() > 0.5) {
return ps;
} else {
return await foo1();
}
}
async function foo2() {
if (Math.random() > 0.5) {
return ps;
} else {
return foo2();
}
} to be fully convinced. |
I believe |
I was wondering if the general case might need to be concerned about side effects, but I found that side effects are not accounted for even in a non async function:
Shouldn't it be true that any call out (e.g. Furthermore, shouldn't any This OPs issue seems correct, it also seems to be about a very special narrow case, so care has to be taken any conclusions from this special case are not extended to cases to which they shouldn't be applied. |
@fatcerberus "except for the specific case where there’s a local catch or finally guarding it.". That can't impact the return type at the |
@Andarist Yeah, I'm not 100% sure but I think you're right. I know that writing
See #9998 for elaboration on why that doesn't happen. Same rationale applies to side effects during processing of |
🔎 Search Terms
async recursive await
🕗 Version & Regression Information
Latest version
⏯ Playground Link
https://www.typescriptlang.org/play?#code/PTAEEsDsDMFMCcDOoAuBPADrUB3cKALAewFcVQBDHC-AKAsTUgGNRoSWVwjJR5ZmARgAUASlABvWqBkRooYQFkKhAHTwKkACZEAtmNAAeUAAZVAVnFTZNvrBQl4vfkLEBuabIC+oWABtEbGtbGX4HJ1AAcgJ-PyJIjxsvWmTaEAgYBGRNNFx8AkpqOgYmVnZObmcBACYDYJlweSUVAnVNHX1xYzNLSU8QsMdeKhpyF1rRRO9fAKD+20GI6Nj4qZlk5KA
💻 Code
🙁 Actual behavior
infers
any
withawait
on self call🙂 Expected behavior
should infer the return type as it does without
await
Additional information about the issue
To my understanding, the code has the exact same runtime behavior, so one would expect the same at compilation.
If working as intended? why?
Thanks.
The text was updated successfully, but these errors were encountered: