我在定义数组的时候,将其定义为:
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(....)