Skip to content

Improve typing for ==, != expressions - #5840

Merged
anandthakker merged 3 commits into
masterfrom
null-equality-expression
Dec 12, 2017
Merged

anandthakker merged 3 commits into
masterfrom
null-equality-expression

Conversation

@anandthakker

@anandthakker anandthakker commented Dec 11, 2017 •

Copy link
Copy Markdown
Contributor

Closes #5761
Closes #5835

The overloads of == and != are now effectively:

  • (T1: Comparable, T2: Comparable) => boolean { T1 == T2 }
  • (Comparable, value) => boolean
  • (value, Comparable) => boolean

Where Comparable = string | number | boolean | null, and evaluation semantics for the value cases are equivalent to Javascript's strict equality (===/!==), i.e., when the value argument's type doesn't match that of the Comparable argument, == evaluates to false, != to true.

An alternative, stricter approach we discussed was to keep the signatures above, but to produce an runtime error in the case of a type mismatch between the value and Comparable arguments -- essentially inserting a type assertion wrapper around the value argument. We went with the less strict approach because:

Closes #5761
Closes #5835

The overloads of == and != are now effectively:
 - `(T1: Comparable, T2: Comparable) => boolean { T1 == T2 }`
 - `(Comparable, value) => boolean`
 - `(value, Comparable) => boolean`

Where `Comparable = string | number | boolean | null`.
@anandthakker
anandthakker force-pushed the null-equality-expression branch from b01bf49 to e81519b Compare December 11, 2017 15:55

@jfirebaugh jfirebaugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per chat, add the alternatives considered and rationale for choosing this one for future us to refer to.

}

possibleOutputs() {
return this.lhs.possibleOutputs().concat(this.rhs.possibleOutputs());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be return [true, false].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants