TS is giving me an error in my Angular 7 project for the sort function below. The error message is: "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type'".
Technically this will work if I comment the function out and then the application run. Once the application is running I can uncomment the function and everything works as expected including the sort function.
Basically I am trying to sort dates on descending order.
this.SortArray = this.project.Attributes.sort(function (a, b) {
return new Date(a.EffDate) - new Date(b.EffDate);
});
(new Date(a.EffDate)).valueOf() - (new Date(b.EffDate)).valueOf()
Note that a)EffDate
should be in ISO 8601 format to work cross-browser and b) sorting alphabetically on ISO 8601 dates works. – Heretic Monkey