Skip to content

Commit f9c029e

Browse files
committed
pick changes
1 parent 1d4dd02 commit f9c029e

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37028,14 +37028,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3702837028
// control flow analysis it is possible for operands to temporarily have narrower types, and those narrower
3702937029
// types may cause the operands to not be comparable. We don't want such errors reported (see #46475).
3703037030
if (!(checkMode && checkMode & CheckMode.TypeOnly)) {
37031-
if (isLiteralExpressionOfObject(left) || isLiteralExpressionOfObject(right)) {
37032-
if (isInJSFile(left) && (operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken)) {
37033-
// we skip the emit for {} == {} in JS files
37034-
}
37035-
else {
37036-
const eqType = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.EqualsEqualsEqualsToken;
37037-
error(errorNode, Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value, eqType ? "false" : "true");
37038-
}
37031+
if (
37032+
(isLiteralExpressionOfObject(left) || isLiteralExpressionOfObject(right)) &&
37033+
// only report for === and !== in JS, not == or !=
37034+
(!isInJSFile(left) || (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken))
37035+
) {
37036+
const eqType = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.EqualsEqualsEqualsToken;
37037+
error(errorNode, Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value, eqType ? "false" : "true");
3703937038
}
3704037039
checkNaNEquality(errorNode, operator, left, right);
3704137040
reportOperatorErrorUnless((left, right) => isTypeEqualityComparableTo(left, right) || isTypeEqualityComparableTo(right, left));
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
=== tests/cases/conformance/salsa/plainJSTypeErrors.js ===
2+
23
// should error
3-
No type information for this code.if ({} === {}) {}
4-
No type information for this code.
5-
No type information for this code.// should not error
6-
No type information for this code.if ({} == {}) {}
7-
No type information for this code.
8-
No type information for this code.
4+
if ({} === {}) {}
5+
6+
// should not error
7+
if ({} == {}) {}
8+

0 commit comments

Comments
 (0)