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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…