I have an object TaskItemVO
with field dueDate
which has the type Date
:
export class TaskItemVO {
public dueDate: Date;
}
I have this method which I call when I try to sort by date but it is not working:
public sortByDueDate(): void {
this.myArray.sort((a: TaskItemVO, b: TaskItemVO) => {
return a.dueDate - b.dueDate;
});
}
I get this error in the return line of method:
The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
So what is the correct way of sorting array by date fields in TypeScript?
undefined
, the class should probably note that in its signature,public dueDate?: Date;
– Heretic Monkey