gpt4 book ai didi

javascript - 类型 '(priority1: number, priority2: number) => number' 的参数不可分配给类型 '(a: unknown, b: unknown) => number' 的参数

转载 作者:行者123 更新时间:2023-11-28 03:07:10 29 4
gpt4 key购买 nike

我收到以下类型错误(TypeScript - 3.7.5)。

error TS2345: Argument of type '(priority1: number, priority2: number) => number' is not assignable to parameter of type '(a: unknown, b: unknown) => number'. Types of parameters 'priority1' and 'a' are incompatible. Type 'unknown' is not assignable to type 'number'.

代码:

public updatePriorities() {
const priorities = this.fetchedData.map((id: IList) => id.priority);
const uniquePriorities = [...new Set(priorities)];
uniquePriorities.sort((priority1: number, priority2: number) => priority1 - priority2);
const updatedPriorities = uniquePriorities.map((priority: number, index: number) => {
return index + 1;
});

uniquePriorities.forEach((id: number, index: number) => {
this.fetchedData.forEach((id1: IList) => {
if (id1.priority === id) {
id1.priority = updatedPriorities[index];
}
});
});
}

最佳答案

我得到了一些东西link这是 TS 设计的限制,所以恐怕没有好的方法来解决它。我们只能等待在下一版本的语言中修复它

关于javascript - 类型 '(priority1: number, priority2: number) => number' 的参数不可分配给类型 '(a: unknown, b: unknown) => number' 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60503638/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com