@@ -26033,7 +26033,7 @@ namespace ts {
2603326033 function getContextualTypeForReturnExpression(node: Expression): Type | undefined {
2603426034 const func = getContainingFunction(node);
2603526035 if (func) {
26036- let contextualReturnType = getContextualReturnType(func);
26036+ const contextualReturnType = getContextualReturnType(func);
2603726037 if (contextualReturnType) {
2603826038 const functionFlags = getFunctionFlags(func);
2603926039 if (functionFlags & FunctionFlags.Generator) { // Generator or AsyncGenerator function
@@ -26042,12 +26042,17 @@ namespace ts {
2604226042 if (!iterationTypes) {
2604326043 return undefined;
2604426044 }
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;
2604626051 }
2604726052
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 )]);
2605126056 }
2605226057
2605326058 return contextualReturnType; // Regular function or Generator function
0 commit comments