@@ -26681,7 +26681,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
26681
26681
function getContextualTypeForReturnExpression(node: Expression): Type | undefined {
26682
26682
const func = getContainingFunction(node);
26683
26683
if (func) {
26684
- let contextualReturnType = getContextualReturnType(func);
26684
+ const contextualReturnType = getContextualReturnType(func);
26685
26685
if (contextualReturnType) {
26686
26686
const functionFlags = getFunctionFlags(func);
26687
26687
if (functionFlags & FunctionFlags.Generator) { // Generator or AsyncGenerator function
@@ -26690,12 +26690,17 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
26690
26690
if (!iterationTypes) {
26691
26691
return undefined;
26692
26692
}
26693
- contextualReturnType = iterationTypes.returnType;
26693
+ if (functionFlags & FunctionFlags.Async) {
26694
+ // unwrap Promise to get the awaited type without the `Awaited<T>` alias
26695
+ const contextualAwaitedType = mapType(iterationTypes.returnType, getAwaitedTypeNoAlias);
26696
+ return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]);
26697
+ }
26698
+ return iterationTypes.returnType;
26694
26699
}
26695
26700
26696
- if (functionFlags & FunctionFlags.Async) { // Async function or AsyncGenerator function
26697
- const contextualAwaitedType = mapType(contextualReturnType, functionFlags & FunctionFlags.Generator ? getAwaitedTypeNoAlias : getAwaitedTypeOfPromise);
26698
- return contextualAwaitedType && getUnionType([contextualAwaitedType , createPromiseLikeType(contextualAwaitedType )]);
26701
+ if (functionFlags & FunctionFlags.Async) {
26702
+ const contextualTypeOfPromise = mapType(contextualReturnType, getAwaitedTypeOfPromise);
26703
+ return contextualTypeOfPromise && getUnionType([contextualTypeOfPromise , createPromiseLikeType(contextualTypeOfPromise )]);
26699
26704
}
26700
26705
26701
26706
return contextualReturnType; // Regular function or Generator function
0 commit comments