-
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
Fixed contextual async return type with unions in context that contain a mix of promise and non-promise types #47683
Fixed contextual async return type with unions in context that contain a mix of promise and non-promise types #47683
Conversation
src/compiler/checker.ts
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
Backlog
milestone (required)main
branchgulp runtests
locallyThis potentially fixes #47682
Commits: