Skip to content

Commit bb5b20b

Browse files
author
Kanchalai Tanglertsampan
committed
Address code review
1 parent 5cc9414 commit bb5b20b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14964,11 +14964,10 @@ namespace ts {
1496414964
}
1496514965
else {
1496614966
let yieldTypes: Type[];
14967-
let returnTypes: Type[];
14967+
let types: Type[];
1496814968
if (functionFlags & FunctionFlags.Generator) { // Generator or AsyncGenerator function
14969-
yieldTypes = checkAndAggregateYieldOperandTypes(func, contextualMapper);
14970-
returnTypes = checkAndAggregateReturnExpressionTypes(func, contextualMapper);
14971-
if (yieldTypes.length === 0 && (!returnTypes || returnTypes.length === 0)) {
14969+
types = concatenate(checkAndAggregateYieldOperandTypes(func, contextualMapper), checkAndAggregateReturnExpressionTypes(func, contextualMapper));
14970+
if (!types || types.length === 0) {
1497214971
const iterableIteratorAny = functionFlags & FunctionFlags.Async
1497314972
? createAsyncIterableIteratorType(anyType) // AsyncGenerator function
1497414973
: createIterableIteratorType(anyType); // Generator function
@@ -14980,22 +14979,22 @@ namespace ts {
1498014979
}
1498114980
}
1498214981
else {
14983-
returnTypes = checkAndAggregateReturnExpressionTypes(func, contextualMapper);
14984-
if (!returnTypes) {
14982+
types = checkAndAggregateReturnExpressionTypes(func, contextualMapper);
14983+
if (!types) {
1498514984
// For an async function, the return type will not be never, but rather a Promise for never.
1498614985
return functionFlags & FunctionFlags.Async
1498714986
? createPromiseReturnType(func, neverType) // Async function
1498814987
: neverType; // Normal function
1498914988
}
14990-
if (returnTypes.length === 0) {
14989+
if (types.length === 0) {
1499114990
// For an async function, the return type will not be void, but rather a Promise for void.
1499214991
return functionFlags & FunctionFlags.Async
1499314992
? createPromiseReturnType(func, voidType) // Async function
1499414993
: voidType; // Normal function
1499514994
}
1499614995
}
1499714996
// Return a union of the return expression types.
14998-
type = getUnionType(yieldTypes ? yieldTypes.concat(returnTypes) : returnTypes, /*subtypeReduction*/ true);
14997+
type = getUnionType(yieldTypes ? yieldTypes.concat(types) : types, /*subtypeReduction*/ true);
1499914998

1500014999
if (functionFlags & FunctionFlags.Generator) { // AsyncGenerator function or Generator function
1500115000
type = functionFlags & FunctionFlags.Async

0 commit comments

Comments
 (0)