鸿蒙开发报错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() 转成字符串
相关推荐
万少5 小时前
HarmonyOS官方模板集成创新活动-流蓝卡片
前端·harmonyos
FrameNotWork11 小时前
HarmonyOS 与 Android 架构对比:从“写页面”到“设计系统”的差异
android·架构·harmonyos
supe_rNiu11 小时前
鸿蒙版本 wanAndroid客户端
安卓·harmonyos·鸿蒙
Swift社区12 小时前
HarmonyOS 文件权限管理实战详解(含可运行 Demo)
华为·harmonyos
搬砖的kk16 小时前
鸿蒙PC端C++开发实战:轻量级网络端口扫描工具
华为·harmonyos
马剑威(威哥爱编程)18 小时前
【鸿蒙学习笔记】基于HarmonyOS实现申请Push Token的功能
笔记·学习·harmonyos
不爱吃糖的程序媛18 小时前
鸿蒙PC端运行C语言程序:从编译到部署的全流程实战
c语言·华为·harmonyos
进击的前栈18 小时前
Flutter跨平台滚动视图scrollview_demo鸿蒙化使用指南
flutter·华为·harmonyos
特立独行的猫a18 小时前
移植FFmpeg最新 8.1版本到鸿蒙PC(OpenHarmony)平台完整指南
ffmpeg·harmonyos·移植·交叉编译·鸿蒙pc
w1395485642219 小时前
Flutter跨平台路径解析鸿蒙化使用指南
flutter·华为·harmonyos