-
Notifications
You must be signed in to change notification settings - Fork 12.8k
return type of function returning a promise or a an empty object is incorrectly inferred unless promise is awaited #54524
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
IMO this is as expected. The type |
Why was that working in 4.9? It seems to be a quite big change and as I mentioned I haven't found anything in release notes that could be related to it, am i missing something? |
As per Ryan wrote: #50171 (comment)
TypeScript makes no guarantees when subtype reduction happens, and it can change between versions. It's an internal detail of the compiler. Both results are equally valid, just one is undesirable in your case. |
I see, I guess nothing I can do about it One question though - snippet with |
IIRC subtyping rules were changed somewhere around TS 5.0 for Note that |
I'm actually using |
This issue has been marked as 'Not a Defect' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
function, return type, await, empty object
π Version & Regression Information
Nothing in the TS 5.0 release notes seems to be related to this change of the behaviour
β― Playground Link
π» Code
playground, TS 4.9
playground, TS 5.0
π Actual behavior
Function's return type is
Promise<{}>
π Expected behavior
Function's return type should be
Promise<{ [key in string]: unknown }>
Here's the code that's more close to the actual use case:
playground, TS 4.9
playground, TS 5.0
This is a pattern I'm using in multiple places in my app with TS 4.9, and if I wanted to upgrde to TS 5.0 I'd need to add
await
before everygetData()
call, which I know I can do automatically using eslint, but I don't think that should be necessaryThe text was updated successfully, but these errors were encountered: