Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if ((typeof foo) === "string") {

} else {
foo;
>foo : string
>foo : never
}

if (typeof foo === ("string")) {
Expand All @@ -33,6 +33,6 @@ if (typeof foo === ("string")) {

} else {
foo;
>foo : string
>foo : never
}

This file was deleted.