鸿蒙开发报错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() 转成字符串
相关推荐
TT_Close2 小时前
【Flutter×鸿蒙】debug 包也要签名,这点和 Android 差远了
android·flutter·harmonyos
TT_Close18 小时前
【Flutter×鸿蒙】FVM 不认鸿蒙 SDK?4步手动塞进去
flutter·swift·harmonyos
hqk20 小时前
鸿蒙项目实战:手把手带你实现 WanAndroid 布局与交互
android·前端·harmonyos
TT_Close20 小时前
【Flutter×鸿蒙】一个"插队"技巧,解决90%的 command not found
flutter·harmonyos
Hcourage2 天前
鸿蒙工程获取C/C++代码覆盖
harmonyos
二流小码农2 天前
鸿蒙开发:上传一张参考图片便可实现页面功能
android·ios·harmonyos
万少3 天前
HarmonyOS 开发必会 5 种 Builder 详解
前端·harmonyos
Huang兄3 天前
鸿蒙-List和Grid拖拽排序:仿微信小程序删除效果
harmonyos·arkts·arkui
anyup4 天前
🔥2026最推荐的跨平台方案:H5/小程序/App/鸿蒙,一套代码搞定
前端·uni-app·harmonyos
Ranger09294 天前
鸿蒙开发新范式:Gpui
rust·harmonyos