diff --git a/internal/binder/binder.go b/internal/binder/binder.go index 5e3dcdbcda..18520cd2e9 100644 --- a/internal/binder/binder.go +++ b/internal/binder/binder.go @@ -2686,9 +2686,11 @@ func isNarrowingBinaryExpression(expr *ast.BinaryExpression) bool { case ast.KindEqualsToken, ast.KindBarBarEqualsToken, ast.KindAmpersandAmpersandEqualsToken, ast.KindQuestionQuestionEqualsToken: return containsNarrowableReference(expr.Left) case ast.KindEqualsEqualsToken, ast.KindExclamationEqualsToken, ast.KindEqualsEqualsEqualsToken, ast.KindExclamationEqualsEqualsToken: - return isNarrowableOperand(expr.Left) || isNarrowableOperand(expr.Right) || - isNarrowingTypeOfOperands(expr.Right, expr.Left) || isNarrowingTypeOfOperands(expr.Left, expr.Right) || - (ast.IsBooleanLiteral(expr.Right) && isNarrowingExpression(expr.Left) || ast.IsBooleanLiteral(expr.Left) && isNarrowingExpression(expr.Right)) + left := ast.SkipParentheses(expr.Left) + right := ast.SkipParentheses(expr.Right) + return isNarrowableOperand(left) || isNarrowableOperand(right) || + isNarrowingTypeOfOperands(right, left) || isNarrowingTypeOfOperands(left, right) || + (ast.IsBooleanLiteral(right) && isNarrowingExpression(left) || ast.IsBooleanLiteral(left) && isNarrowingExpression(right)) case ast.KindInstanceOfKeyword: return isNarrowableOperand(expr.Left) case ast.KindInKeyword: diff --git a/testdata/baselines/reference/submodule/compiler/narrowingTypeofParenthesized1.types b/testdata/baselines/reference/submodule/compiler/narrowingTypeofParenthesized1.types index fb043315ca..91ebadef01 100644 --- a/testdata/baselines/reference/submodule/compiler/narrowingTypeofParenthesized1.types +++ b/testdata/baselines/reference/submodule/compiler/narrowingTypeofParenthesized1.types @@ -18,7 +18,7 @@ if ((typeof foo) === "string") { } else { foo; ->foo : string +>foo : never } if (typeof foo === ("string")) { @@ -33,6 +33,6 @@ if (typeof foo === ("string")) { } else { foo; ->foo : string +>foo : never } diff --git a/testdata/baselines/reference/submodule/compiler/narrowingTypeofParenthesized1.types.diff b/testdata/baselines/reference/submodule/compiler/narrowingTypeofParenthesized1.types.diff deleted file mode 100644 index 7a39c0b9aa..0000000000 --- a/testdata/baselines/reference/submodule/compiler/narrowingTypeofParenthesized1.types.diff +++ /dev/null @@ -1,18 +0,0 @@ ---- old.narrowingTypeofParenthesized1.types -+++ new.narrowingTypeofParenthesized1.types -@@= skipped -17, +17 lines =@@ - - } else { - foo; -->foo : never -+>foo : string - } - - if (typeof foo === ("string")) { -@@= skipped -15, +15 lines =@@ - - } else { - foo; -->foo : never -+>foo : string - }