@@ -26033,7 +26033,7 @@ namespace ts {
26033
26033
function getContextualTypeForReturnExpression(node: Expression): Type | undefined {
26034
26034
const func = getContainingFunction(node);
26035
26035
if (func) {
26036
- let contextualReturnType = getContextualReturnType(func);
26036
+ const contextualReturnType = getContextualReturnType(func);
26037
26037
if (contextualReturnType) {
26038
26038
const functionFlags = getFunctionFlags(func);
26039
26039
if (functionFlags & FunctionFlags.Generator) { // Generator or AsyncGenerator function
@@ -26042,12 +26042,17 @@ namespace ts {
26042
26042
if (!iterationTypes) {
26043
26043
return undefined;
26044
26044
}
26045
- contextualReturnType = iterationTypes.returnType;
26045
+ if (functionFlags & FunctionFlags.Async) {
26046
+ // unwrap Promise to get the awaited type without the `Awaited<T>` alias
26047
+ const contextualAwaitedType = mapType(iterationTypes.returnType, getAwaitedTypeNoAlias);
26048
+ return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]);
26049
+ }
26050
+ return iterationTypes.returnType;
26046
26051
}
26047
26052
26048
- if (functionFlags & FunctionFlags.Async) { // Async function or AsyncGenerator function
26049
- const contextualAwaitedType = mapType(contextualReturnType, functionFlags & FunctionFlags.Generator ? getAwaitedTypeNoAlias : getAwaitedTypeOfPromise);
26050
- return contextualAwaitedType && getUnionType([contextualAwaitedType , createPromiseLikeType(contextualAwaitedType )]);
26053
+ if (functionFlags & FunctionFlags.Async) {
26054
+ const contextualTypeOfPromise = mapType(contextualReturnType, getAwaitedTypeOfPromise);
26055
+ return contextualTypeOfPromise && getUnionType([contextualTypeOfPromise , createPromiseLikeType(contextualTypeOfPromise )]);
26051
26056
}
26052
26057
26053
26058
return contextualReturnType; // Regular function or Generator function
0 commit comments