鸿蒙开发报错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() 转成字符串
相关推荐
xiaocao_10234 小时前
鸿蒙手机上使用的备忘录怎么导出来?
华为·智能手机·harmonyos
春卷同学6 小时前
打砖块 - Electron for 鸿蒙PC项目实战案例
android·electron·harmonyos
春卷同学9 小时前
Electron for鸿蒙PC开发的骰子游戏应用
游戏·electron·harmonyos
春卷同学9 小时前
Electron for 鸿蒙pc开发的二十一点游戏
游戏·electron·harmonyos
不老刘10 小时前
react native for OpenHarmony iconfont 图标不显示问题
react native·harmonyos·iconfont
汉堡黄•᷄ࡇ•᷅10 小时前
鸿蒙开发: 案例集合List:ListItem侧滑(删除、收藏)
harmonyos·鸿蒙·鸿蒙系统
春卷同学10 小时前
拼图游戏 - Electron for 鸿蒙PC项目实战案例
javascript·electron·harmonyos
春卷同学11 小时前
基于 Electron 开发的跨平台鸿蒙PC端数字猜谜游戏桌面应用
游戏·electron·harmonyos
盐焗西兰花11 小时前
鸿蒙学习实战之路 - 轮播图组件实现
学习·华为·harmonyos
ChinaDragon11 小时前
HarmonyOS:转场动画
harmonyos