@@ -14963,10 +14963,12 @@ namespace ts {
14963
14963
}
14964
14964
}
14965
14965
else {
14966
- let types: Type[];
14966
+ let yieldTypes: Type[];
14967
+ let returnTypes: Type[];
14967
14968
if (functionFlags & FunctionFlags.Generator) { // Generator or AsyncGenerator function
14968
- types = checkAndAggregateYieldOperandTypes(func, contextualMapper);
14969
- if (types.length === 0) {
14969
+ yieldTypes = checkAndAggregateYieldOperandTypes(func, contextualMapper);
14970
+ returnTypes = checkAndAggregateReturnExpressionTypes(func, contextualMapper);
14971
+ if (yieldTypes.length === 0 && (!returnTypes || returnTypes.length === 0)) {
14970
14972
const iterableIteratorAny = functionFlags & FunctionFlags.Async
14971
14973
? createAsyncIterableIteratorType(anyType) // AsyncGenerator function
14972
14974
: createIterableIteratorType(anyType); // Generator function
@@ -14978,22 +14980,22 @@ namespace ts {
14978
14980
}
14979
14981
}
14980
14982
else {
14981
- types = checkAndAggregateReturnExpressionTypes(func, contextualMapper);
14982
- if (!types ) {
14983
+ returnTypes = checkAndAggregateReturnExpressionTypes(func, contextualMapper);
14984
+ if (!returnTypes ) {
14983
14985
// For an async function, the return type will not be never, but rather a Promise for never.
14984
14986
return functionFlags & FunctionFlags.Async
14985
14987
? createPromiseReturnType(func, neverType) // Async function
14986
14988
: neverType; // Normal function
14987
14989
}
14988
- if (types .length === 0) {
14990
+ if (returnTypes .length === 0) {
14989
14991
// For an async function, the return type will not be void, but rather a Promise for void.
14990
14992
return functionFlags & FunctionFlags.Async
14991
14993
? createPromiseReturnType(func, voidType) // Async function
14992
14994
: voidType; // Normal function
14993
14995
}
14994
14996
}
14995
14997
// Return a union of the return expression types.
14996
- type = getUnionType(types , /*subtypeReduction*/ true);
14998
+ type = getUnionType(yieldTypes ? yieldTypes.concat(returnTypes) : returnTypes , /*subtypeReduction*/ true);
14997
14999
14998
15000
if (functionFlags & FunctionFlags.Generator) { // AsyncGenerator function or Generator function
14999
15001
type = functionFlags & FunctionFlags.Async
0 commit comments