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

Relax typing for equality and order expressions #6459

Closed
anandthakker opened this issue Apr 5, 2018 · 2 comments
Closed

Relax typing for equality and order expressions #6459

anandthakker opened this issue Apr 5, 2018 · 2 comments
Labels
api 📝 cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.)

Comments

@anandthakker
Copy link
Contributor

#5840 relaxed the typing for == and !=, making it possible to do:

  • ["==", ["get", "x"], 1] without a type annotation for the "get" expression.
  • ["==", ["get", "x"], null]

Some ways we could consider further relaxing typing for comparisons:

  • Make an analogous change for >, <, etc., allowing (number | string, value), (value, number | string) so that [">", ["get", "x"], 5] is valid.
  • Also allow (value, value) for equality and order expressions, so that . e.g. ["==", ["get", "x"], ["get", "y"]] is valid.
@anandthakker
Copy link
Contributor Author

Make an analogous change for >, <, etc., allowing (number | string, value), (value, number | string) so that [">", ["get", "x"], 5] is valid.

The main question here is what to do when you end up with a type mismatch between the two arguments being compared. Simply evaluating to false, like we do for ==/!=, is more misleading in this case. On the other hand, adding an implicit type assertion, and thus erroring out of the expression when there's a type mismatch, would make the behavior of > inconsistent with ==, which would also be surprising.

@anandthakker anandthakker added cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) api 📝 labels Apr 5, 2018
@anandthakker
Copy link
Contributor Author

On the other hand, adding an implicit type assertion, and thus erroring out of the expression when there's a type mismatch, would make the behavior of > inconsistent with ==, which would also be surprising.

This is the option I lean towards: [">", ["get", "x"], 10] gets parsed as [">", ["number", ["get", "x"]], 10].

It's not the same way we handle == comparisons between different types, but I suspect that for ordering operators, the alternative option of just evaluating to false is likely to create more confusion: E.g., I wrote [">", ["get", "x"], 10], so why did my feature with {properties: { x: '100'}} return false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api 📝 cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.)
Projects
None yet
Development

No branches or pull requests

1 participant