python
Argument of type '(item: ObjectData) => number' is not assignable to parameter of type '(item: any, index: number) => string'.
Type 'number' is not assignable to type 'string'. <ArkTSCheck>
报错代码
js
@Link lists:Array<ObjectData>;
ForEach(this.lists, (item: ObjectData) => {
this.taskItem(item)()
}, (item: ObjectData) => item.id)
修改代码
js
ForEach(this.lists,(item: ObjectData) => {
this.taskItem(item)
}, (item: ObjectData) => item.id.toString())
📌 总结一下:
错误原因 | 解决方式 |
---|---|
item.id 是 number,但 ForEach 要求 string | 加 .toString() 转成字符串 |