Fixed contextual async return type with unions in context that contain a mix of promise and non-promise types#47683
Conversation
| const contextualAwaitedType = mapType(contextualReturnType, getAwaitedTypeNoAlias); | ||
| return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]); | ||
| if (functionFlags & FunctionFlags.Async) { | ||
| const contextualTypeOfPromise = mapType(contextualReturnType, getAwaitedTypeOfPromise); |
There was a problem hiding this comment.
The main and only change here is that for async non-generator functions I use mapType with getAwaitedTypeOfPromise. This ensures that I only unwrap promise types instead of unwrapping any types with Awaited<T>.
It IMHO conceptually makes sense because if we deal with unions we can only return a Promise type that includes Promise-wrapped types. If a member of a union is of a different type then async method just won't be able to match it as async always returns a Promise.
|
@rbuckton friendly 🏓 would love to hear out your thoughts about this PR :) |
|
@Azarattum I’ve checked and those are unrelated |
|
@rbuckton friendly 🏓 |
…ion when the contextual type is a union of a promise and of a different type
…ion when unions are involved
…ol flow more clear
0ea6851 to
f4b2ec7
Compare
|
since #51196 supersedes this PR, do you want to close it? |
|
Ye, I think that this other PR is a better one. Let's close this one. |
Please verify that:
Backlogmilestone (required)mainbranchgulp runtestslocallyThis potentially fixes #47682
Commits: