Skip to content

Disallow Array.sort on non-comparable Array #1

Open
@alexeagle

Description

@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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions