鸿蒙开发报错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() 转成字符串
相关推荐
sam.li21 小时前
鸿蒙HAR对外发布安全流程
安全·华为·harmonyos
sam.li21 小时前
鸿蒙APP安全体系
安全·华为·harmonyos
ChinaDragon1 天前
HarmonyOS:通过组件导航设置自定义区域
harmonyos
人工智能知识库1 天前
华为HCIP-HarmonyOS Application Developer题库 H14-231 (26年最新带解析)
华为·harmonyos·hcip-harmonyos·h14-231
搬砖的kk1 天前
鸿蒙 PC 版 DevEco Studio 使用 OHPM 下载三方库教程
华为·harmonyos
游戏技术分享2 天前
【鸿蒙游戏技术分享 第75期】AGC后台批量导入商品失败,提示“参数错误”
游戏·华为·harmonyos
No Silver Bullet2 天前
HarmonyOS NEXT开发进阶(十七):WebView 拉起 H5 页面
华为·harmonyos
liuhaikang2 天前
【鸿蒙HarmonyOS Next App实战开发】口语小搭档——应用技术实践
harmonyos
liuhaikang2 天前
鸿蒙VR视频播放库——md360player
音视频·vr·harmonyos
飞露2 天前
鸿蒙Preview预览文件失败原因
华为·harmonyos