mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 10:43:51 -05:00
Add check for reference-compared literals to JS files (#49164)
This commit is contained in:
@@ -37024,7 +37024,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// control flow analysis it is possible for operands to temporarily have narrower types, and those narrower
|
||||
// types may cause the operands to not be comparable. We don't want such errors reported (see #46475).
|
||||
if (!(checkMode && checkMode & CheckMode.TypeOnly)) {
|
||||
if (isLiteralExpressionOfObject(left) || isLiteralExpressionOfObject(right)) {
|
||||
if (
|
||||
(isLiteralExpressionOfObject(left) || isLiteralExpressionOfObject(right)) &&
|
||||
// only report for === and !== in JS, not == or !=
|
||||
(!isInJSFile(left) || (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken))
|
||||
) {
|
||||
const eqType = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.EqualsEqualsEqualsToken;
|
||||
error(errorNode, Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value, eqType ? "false" : "true");
|
||||
}
|
||||
|
||||
@@ -1430,6 +1430,8 @@ export const plainJSErrors: Set<number> = new Set([
|
||||
Diagnostics.Class_constructor_may_not_be_a_generator.code,
|
||||
Diagnostics.Class_constructor_may_not_be_an_accessor.code,
|
||||
Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
||||
// Type errors
|
||||
Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value.code,
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user