鸿蒙开发报错Argument of type '(item: ObjectData) => number' is not xxxx

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() 转成字符串
相关推荐
libo_202535 分钟前
HarmonyOS5 隐私标签验证:用静态扫描确保元服务声明权限与实际匹配
harmonyos
别说我什么都不会2 小时前
【OpenHarmony】 鸿蒙网络请求库之ohos_ntp
网络协议·harmonyos
很萌很帅的恶魔神ww3 小时前
HarmonyOS Next 之-组件之弹窗
harmonyos
很萌很帅的恶魔神ww3 小时前
HarmonyOS Next 底部 Tab 栏组件开发实战
harmonyos
云_杰3 小时前
HarmonyOS ——Telephony Kit(蜂窝通信服务)教程
harmonyos
很萌很帅的恶魔神ww3 小时前
HarmonyOS Next 之轮播图开发指南(Swiper组件)
harmonyos
别说我什么都不会4 小时前
【OpenHarmony】 鸿蒙网络请求库之eventsource
harmonyos
颜颜颜yan_6 小时前
【HarmonyOS5】掌握UIAbility启动模式:Singleton、Specified、Multiton
后端·架构·harmonyos
二蛋和他的大花7 小时前
HarmonyOS运动开发:深度解析文件预览的正确姿势
华为·harmonyos
长弓三石8 小时前
鸿蒙网络编程系列53-仓颉版TCP连接超时分析示例
前端·harmonyos