Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour between double and triple equals #8280

Open
augusto-altman opened this issue Feb 4, 2020 · 0 comments
Open

Inconsistent behaviour between double and triple equals #8280

augusto-altman opened this issue Feb 4, 2020 · 0 comments

Comments

@augusto-altman
Copy link

augusto-altman commented Feb 4, 2020

Flow version: v0.117.1

Expected behavior

It consistently fails when comparing a number and a string.

Actual behavior

The current behavior is absolutely inconsistent, mainly between the behavior of double and triple equals comparison, but it is also inconsistent when using triple equals against a number literal. See the following cases:

  • When doing someNumber == someString it fails with the message Cannot compare string [1] to number [2].

  • When doing someNumber === someString it doesn't fail at all.

  • When doing if(someString === 3) it fails with the message number literal 3 [1] is incompatible with string [2].

  • When doing console.log(someString === 3) it doesn't fail at all.

  • When doing if(someString === someNumber) and console.log(someString === someNumber) it doesn't fail at all.

I consider this is especially important due to the following two facts:

  1. Type refinements require triple equals. See this issue
  2. The behavior is solid and consistent in Typescript. See this equivalent playground
@augusto-altman augusto-altman changed the title Inconsistent behaviour between double and triple equal Inconsistent behaviour between double and triple equals Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant