Contextual generic return type of an async function includes union members from the context that it shouldn't #47682
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Milestone
Bug Report
π Search Terms
contextual typing, generic, async, return type, union
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
TS playground (latest)
TS playground (nightly)
π» Code
π Actual behavior
Both tests fail to compile and the reported error looks bizzare(-ish):
For some reason, the return type here didn't narrow the contextual union to include only Promise(-like?) members and dragged the whole
Awaited<Union>
to the computed contextual type. And this has caused an assignability problem.Note that this "only" happens with
Promise.reject
, it's not reproducible withPromise.resolve
and other similar types. My guess is that it's becausePromise.reject
contains a generic only at the return type position and this is what makes this issue manifest somehow.π Expected behavior
No error should be reported because this is valid code and it looks like sufficient information has been provided in the context for this to be narrowed down properly~.
While looking into this problem I've poked around the internals of TS and figured out that this might be a potential fix for this issue: #47683
The text was updated successfully, but these errors were encountered: