鸿蒙开发报错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() 转成字符串
相关推荐
宇宙最强的无天佛祖2 小时前
鸿蒙开发中快速获取相册图片的缩略图
harmonyos
冰冷的bin3 小时前
【Harmony】鸿蒙相机拍照使用简单示例
数码相机·华为·harmonyos
爱笑的眼睛118 小时前
HarmonyOS RemoteWindow远程窗口组件的分布式能力深度解析
华为·harmonyos
爱笑的眼睛1113 小时前
HarmonyOS Badge徽标组件:深入消息提示的实现与优化
华为·harmonyos
爱笑的眼睛1115 小时前
HarmonyOS List组件性能优化:从基础到高级实践
华为·harmonyos
ifeng091816 小时前
HarmonyOS实战项目:打造智能家居控制中心(设备发现与控制)
wpf·智能家居·harmonyos
ifeng091819 小时前
HarmonyOS分布式数据管理——跨设备数据同步实战
harmonyos
ifeng091820 小时前
HarmonyOS实战项目:开发一个分布式新闻阅读客户端
分布式·wpf·harmonyos
小范馆20 小时前
通过 useEventBus 和 useEventCallBack 实现与原生 Android、鸿蒙、iOS 的事件交互
android·ios·harmonyos
爱笑的眼睛1121 小时前
HarmonyOS Text组件样式定制深度解析:从基础到高级实践
华为·harmonyos