Ts数组遍历报错:this expression is not callable

在定义 TypeScript 接口 demo 中,rows 属性为 demo1[], demo2[] 或 demo3[] 的联合类型,导致使用 map 方法时出现类型不兼容错误。解决办法是先对数组进行解构,如 [...demo.rows],然后再调用 map 方法,从而避免类型冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我在定义数组的时候,将其定义为:

export interface demo {
  count: number;
  rows: demo1[] | demo2[] | demo3[];
}

对rows使用map方法

demo.rows.map(....)

会报错:

app/common/utils/asset.ts:598:14 - error TS2349: This expression is not callable.
Each member of the union type ‘((callbackfn: (value: IssueRowsItem, index: number, array: IssueRowsItem[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: Codebase, index: number, array: Codebase[]) => U, thisArg?: any) => U[]) | … 4 more … | ((callbackfn: (value: Dependency, index: number, array: Dependency[]) => U, thisArg?: a…’ has signatures, but none of those signatures are compatible with each other.
在这里插入图片描述

解决方法:
将数组解构到新数组后遍历

[...demo.rows].map(....)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KaiSarH

如果觉得文章不错,可以支持下~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值