@@ -19244,7 +19244,9 @@ namespace ts {
19244
19244
19245
19245
// Get the types from all cases in a switch on `typeof`. An
19246
19246
// `undefined` element denotes an explicit `default` clause.
19247
- function getSwitchClauseTypeOfWitnesses(switchStatement: SwitchStatement): (string | undefined)[] {
19247
+ function getSwitchClauseTypeOfWitnesses(switchStatement: SwitchStatement, retainDefault: false): string[];
19248
+ function getSwitchClauseTypeOfWitnesses(switchStatement: SwitchStatement, retainDefault: boolean): (string | undefined)[];
19249
+ function getSwitchClauseTypeOfWitnesses(switchStatement: SwitchStatement, retainDefault: boolean): (string | undefined)[] {
19248
19250
const witnesses: (string | undefined)[] = [];
19249
19251
for (const clause of switchStatement.caseBlock.clauses) {
19250
19252
if (clause.kind === SyntaxKind.CaseClause) {
@@ -19254,7 +19256,7 @@ namespace ts {
19254
19256
}
19255
19257
return emptyArray;
19256
19258
}
19257
- witnesses.push(/*explicitDefaultStatement*/ undefined);
19259
+ if (retainDefault) witnesses.push(/*explicitDefaultStatement*/ undefined);
19258
19260
}
19259
19261
return witnesses;
19260
19262
}
@@ -20359,7 +20361,7 @@ namespace ts {
20359
20361
}
20360
20362
20361
20363
function narrowBySwitchOnTypeOf(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): Type {
20362
- const switchWitnesses = getSwitchClauseTypeOfWitnesses(switchStatement);
20364
+ const switchWitnesses = getSwitchClauseTypeOfWitnesses(switchStatement, /*retainDefault*/ true );
20363
20365
if (!switchWitnesses.length) {
20364
20366
return type;
20365
20367
}
@@ -26772,8 +26774,7 @@ namespace ts {
26772
26774
function computeExhaustiveSwitchStatement(node: SwitchStatement): boolean {
26773
26775
if (node.expression.kind === SyntaxKind.TypeOfExpression) {
26774
26776
const operandType = getTypeOfExpression((node.expression as TypeOfExpression).expression);
26775
- // This cast is safe because the switch is possibly exhaustive and does not contain a default case, so there can be no undefined.
26776
- const witnesses = <string[]>getSwitchClauseTypeOfWitnesses(node);
26777
+ const witnesses = getSwitchClauseTypeOfWitnesses(node, /*retainDefault*/ false);
26777
26778
// notEqualFacts states that the type of the switched value is not equal to every type in the switch.
26778
26779
const notEqualFacts = getFactsFromTypeofSwitch(0, 0, witnesses, /*hasDefault*/ true);
26779
26780
const type = getBaseConstraintOfType(operandType) || operandType;
0 commit comments