将下划线转换为Javascript

问题描述 投票:2回答:1

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

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

TS2362:算术运算的左侧必须为'any','number','bigint'或枚举类型。

下划线版本

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));

enter image description here

有人可以帮我这里有什么问题吗?

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

javascript typescript underscore.js
1个回答
2
投票
尝试此:

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

© www.soinside.com 2019 - 2024. All rights reserved.