鸿蒙开发报错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() 转成字符串
相关推荐
轻口味35 分钟前
HarmonyOS 6.1 全栈实战录 - 14 渲染树透镜:FrameNode 渲染状态感知与高性能 UI 调优实战
ui·华为·harmonyos
HwJack201 小时前
HarmonyOS NEXT 游戏APP开发中如何正确拦截退出手势
游戏·华为·harmonyos
HwJack201 小时前
HarmonyOS APP开发中ArkTS/JS 类型错误全景拆解
javascript·华为·harmonyos
lqj_本人2 小时前
鸿蒙PC:鸿蒙版本 Electron 框架环境搭建并且实现 XH 笔记应用
笔记·electron·harmonyos
不爱吃糖的程序媛2 小时前
特色软件 | 补齐 鸿蒙 PC 开发短板,Harmonybrew 的环境适配方案
华为·harmonyos
Python私教2 小时前
端侧 AIGC 进 App:HarmonyOS Data Augmentation Kit 实测复盘
华为·aigc·harmonyos
前端不太难3 小时前
如何优化鸿蒙 App 的启动速度?
华为·状态模式·harmonyos
想你依然心痛3 小时前
HarmonyOS 6(API 23)实战:基于悬浮导航、沉浸光感与HMAF的“译界智脑“——PC端AI智能体沉浸式智能翻译与跨语言协作工作台
人工智能·华为·ar·harmonyos
Python私教3 小时前
鸿蒙智能体框架 HMAF 上手:从 Agent 注册到 ArkTS 联调
华为·harmonyos
nashane3 小时前
HarmonyOS 6学习:外接键盘CapsLock键“失灵”?一招解锁大写输入
学习·华为·计算机外设·harmonyos