鸿蒙开发报错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() 转成字符串
相关推荐
Hello_MyDream2 小时前
鸿蒙getContext(this)弃用后的替代方法
华为·harmonyos
前端世界4 小时前
鸿蒙在教育场景的落地实践:智慧课堂的分布式设计思路
分布式·华为·harmonyos
Lancker5 小时前
拥抱纯血鸿蒙经验分享 实战鸿蒙2025激励计划上架8个鸿蒙APP
华为·harmonyos
liuhaikang6 小时前
【鸿蒙HarmonyOS Next App实战开发】卡片工坊 应用技术实践
华为·harmonyos
ChinaDragon7 小时前
HarmonyOS:短时任务(ArkTS)
harmonyos
ChinaDragon7 小时前
HarmonyOS:长时任务(ArkTS)
harmonyos
liuhaikang7 小时前
【鸿蒙HarmonyOS Next App实战开发】古诗书院 应用技术实践
华为·harmonyos
胡琦博客8 小时前
基于开发者空间鸿蒙云手机体验鸿蒙开发
华为·智能手机·harmonyos
namehao46519 小时前
从HarmonyOS基础认证到赋能资源建设:我的鸿蒙开发进阶之路
华为·harmonyos
前端不太难21 小时前
用一张“状态扩散图”,定位 RN 列表性能风险
react.js·harmonyos