@@ -8364,13 +8364,18 @@ namespace ts {
8364
8364
// each antecedent code path.
8365
8365
const antecedentTypes: Type[] = [];
8366
8366
let subtypeReduction = false;
8367
+ let firstAntecedentType: FlowType;
8367
8368
flowLoopNodes[flowLoopCount] = flow;
8368
8369
flowLoopKeys[flowLoopCount] = key;
8369
8370
flowLoopTypes[flowLoopCount] = antecedentTypes;
8370
8371
for (const antecedent of flow.antecedents) {
8371
8372
flowLoopCount++;
8372
- const type = getTypeFromFlowType( getTypeAtFlowNode(antecedent) );
8373
+ const flowType = getTypeAtFlowNode(antecedent);
8373
8374
flowLoopCount--;
8375
+ if (!firstAntecedentType) {
8376
+ firstAntecedentType = flowType;
8377
+ }
8378
+ const type = getTypeFromFlowType(flowType);
8374
8379
// If we see a value appear in the cache it is a sign that control flow analysis
8375
8380
// was restarted and completed by checkExpressionCached. We can simply pick up
8376
8381
// the resulting type and bail out.
@@ -8393,7 +8398,13 @@ namespace ts {
8393
8398
break;
8394
8399
}
8395
8400
}
8396
- return cache[key] = getUnionType(antecedentTypes, subtypeReduction);
8401
+ // The result is incomplete if the first antecedent (the non-looping control flow path)
8402
+ // is incomplete.
8403
+ const result = getUnionType(antecedentTypes, subtypeReduction);
8404
+ if (isIncomplete(firstAntecedentType)) {
8405
+ return createFlowType(result, /*incomplete*/ true);
8406
+ }
8407
+ return cache[key] = result;
8397
8408
}
8398
8409
8399
8410
function isMatchingReferenceDiscriminant(expr: Expression) {
0 commit comments