Closed as not planned
Closed as not planned
Description
🔎 Search Terms
Rule 2839
does not seem to know about Javascript's loose equality semantics for objects. It falsely states that:
This condition will always return 'false' since JavaScript compares objects by reference, not value.
Below are some examples that trip this diagnostic even though they evaluate to true.
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about 5.20
⏯ Playground Link
💻 Code
'[object Object]' == {}
"foo" == { toString: ()=>"foo" }
"foo" == { valueOf: ()=>"foo" }
"foo" == { [Symbol.toPrimitive]: ()=>"foo" }
1 == { [Symbol.toPrimitive]: ()=>1 }
🙁 Actual behavior
The expressions all evaluate to true, but TypeScript erroneously reports:
This condition will always return 'false' since JavaScript compares objects by reference, not value.
And:
This comparison appears to be unintentional because the types 'string' and '{ toString: () => string; }' have no overlap.
🙂 Expected behavior
These error messages should not be shown.