You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above code snippet produces an error on the == condition: This condition will always return 'false' since JavaScript compares objects by reference, not value.(2839) which would lead the user to believe that console.log(...) would always print false. In reality, the line prints true. The object on the right is coerced to a string using the valueOf() method so the comparison becomes 'foo' == 'foo' which is true, but TypeScript claims otherwise.
π Expected behavior
Even if TypeScript cannot determine that this condition would be always true given the usage of valueOf, I would expect the error message to say something more like ...may always return false...
instead of the more certain ...will always return false... so that the user is not told that something will certainly happen when it may not.
The text was updated successfully, but these errors were encountered:
What do you propose? The error message is true if you name the method literally anything else, so youβre de facto asking typescript to understand the semantics of valueOf, which it currently doesnβt.
Bug Report
π Search Terms
always false, valueOf, equality
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The above code snippet produces an error on the
==
condition:This condition will always return 'false' since JavaScript compares objects by reference, not value.(2839)
which would lead the user to believe thatconsole.log(...)
would always print false. In reality, the line prints true. The object on the right is coerced to a string using thevalueOf()
method so the comparison becomes'foo' == 'foo'
which is true, but TypeScript claims otherwise.π Expected behavior
Even if TypeScript cannot determine that this condition would be always true given the usage of
valueOf
, I would expect the error message to say something more like...may always return false...
instead of the more certain
...will always return false...
so that the user is not told that something will certainly happen when it may not.The text was updated successfully, but these errors were encountered: