Solution: (Typescript)
(range as Date[]).sort((a, b) => a.valueOf() - b.valueOf());
My first thought was why not just:
(range as Date[]).sort()
But that does not work. Have a look at the MDN documents and you will see the comparison is done with character’s Unicode code.
Try this in your browsers console to see the solution working
const range = [
new Date("2020-09-10"),
new Date("2020-12-20"),
new Date("2020-11-12"),
];
range.sort((a, b) => a.valueOf() - b.valueOf())