将下划线 sortBy 转换为 javascript

Convert underscore sortBy to javasscript

我有一个数组,它是使用 Underscore 的数组函数 _.sortBy() 排序的,我需要将它转换成普通的 JS 函数 .sort()

我的问题是当我将它转换为普通 array.sort() 函数时,我的 IDE (Webstorm) 抛出一个错误:

TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

下划线版本

this.interviewDetails.data = _.sortBy(this.interviewDetails.data, function (o) {
   return new Date(o.timeslot);
});

原版

this.interviewDetails.data.sort((a: any, b: any) => new Date(a.timeslot) - new Date(b.timeslot));

任何人都可以帮助我这里可能有什么问题吗?

PS-请看上图中new Date(a.timeslot)中的红色下划线

试试这个:

this.interviewDetails.data.sort((a: any, b: any) => new Date(a.timeslot).getTime() - new Date(b.timeslot).getTime());