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

Disallow Array.sort on non-comparable Array #1

Open
alexeagle opened this issue Apr 13, 2016 · 0 comments
Open

Disallow Array.sort on non-comparable Array #1

alexeagle opened this issue Apr 13, 2016 · 0 comments

Comments

@alexeagle
Copy link
Owner

@martine says

https://influxdata.com/blog/the-chronograf-files-the-curious-case-of-javascripts-sort/
tldr array.sort() coerces to strings sorts lexicographically, you need to pass a comparator if you want otherwise.

Ideally we could catch this in the type system, e.g. only allow the no-arg sort() for arrays of strings.
But I think you can't express that in the TS type system.
Maybe this is a good motivating example for some sort of fancier static analysis pass -- it needs to know the type of the variable to properly check.

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

No branches or pull requests

1 participant