@@ -16882,7 +16882,8 @@ namespace ts {
16882
16882
let firstDefaultClause: CaseOrDefaultClause;
16883
16883
let hasDuplicateDefaultClause = false;
16884
16884
16885
- let expressionType = checkExpression(node.expression);
16885
+ const expressionType = checkExpression(node.expression);
16886
+ const expressionIsLiteral = isLiteralType(expressionType);
16886
16887
forEach(node.caseBlock.clauses, clause => {
16887
16888
// Grammar check for duplicate default clauses, skip if we already report duplicate default clause
16888
16889
if (clause.kind === SyntaxKind.DefaultClause && !hasDuplicateDefaultClause) {
@@ -16905,14 +16906,14 @@ namespace ts {
16905
16906
// to or from the type of the 'switch' expression.
16906
16907
let caseType = checkExpression(caseClause.expression);
16907
16908
const caseIsLiteral = isLiteralType(caseType);
16908
- const expressionIsLiteral = isLiteralType( expressionType) ;
16909
+ let literalExpressionType = expressionType;
16909
16910
if (!caseIsLiteral || !expressionIsLiteral) {
16910
16911
caseType = caseIsLiteral ? getBaseTypeOfLiteralType(caseType) : caseType;
16911
- expressionType = expressionIsLiteral ? getBaseTypeOfLiteralType(expressionType) : expressionType ;
16912
+ literalExpressionType = getBaseTypeOfLiteralType(expressionType);
16912
16913
}
16913
- if (!isTypeEqualityComparableTo(expressionType , caseType)) {
16914
+ if (!isTypeEqualityComparableTo(literalExpressionType , caseType)) {
16914
16915
// expressionType is not comparable to caseType, try the reversed check and report errors if it fails
16915
- checkTypeComparableTo(caseType, expressionType , caseClause.expression, /*headMessage*/ undefined);
16916
+ checkTypeComparableTo(caseType, literalExpressionType , caseClause.expression, /*headMessage*/ undefined);
16916
16917
}
16917
16918
}
16918
16919
forEach(clause.statements, checkSourceElement);
0 commit comments