Narrow types by typeof operands with extra parenthesis (#60928)

This commit is contained in:
Mateusz Burzyński
2025-01-07 21:26:00 +01:00
committed by GitHub
parent c0b3ff2da1
commit a5196c7d3b
4 changed files with 106 additions and 3 deletions

View File

@@ -1318,9 +1318,11 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsEqualsToken:
return isNarrowableOperand(expr.left) || isNarrowableOperand(expr.right) ||
isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right) ||
(isBooleanLiteral(expr.right) && isNarrowingExpression(expr.left) || isBooleanLiteral(expr.left) && isNarrowingExpression(expr.right));
const left = skipParentheses(expr.left);
const right = skipParentheses(expr.right);
return isNarrowableOperand(left) || isNarrowableOperand(right) ||
isNarrowingTypeofOperands(right, left) || isNarrowingTypeofOperands(left, right) ||
(isBooleanLiteral(right) && isNarrowingExpression(left) || isBooleanLiteral(left) && isNarrowingExpression(right));
case SyntaxKind.InstanceOfKeyword:
return isNarrowableOperand(expr.left);
case SyntaxKind.InKeyword: