TS2345:类型 '(item: cType) => cType' 的参数不可分配给类型 '(value: Object, index: number, array: Object[])



我目前在项目中使用Angular 13和Typescript 4.5.2。

我还使用syncusion库来开发应用程序,其中我使用数据网格组件来处理表数据。

Syncfusion数据网格参考对应的stackblitz

数据中存在的数据。ts文件。我在数据中得到了上述错误。ts文件。正好在下面代码的第二行

type cType = { CustomerID: string, ContactName: string, CustomerName: string };
export const data: Object[] = orderData.map((item: cType) => {
let name: cType = (<cType[]>customerData).filter((cItem: cType) => {
return cItem.CustomerID === item.CustomerID;
})[0];
item.CustomerName = (name || <cType>{}).ContactName;
return item;
});

不能得到确切的想法来破解这个。需要帮助解决

您可以使用以下代码解决此TS错误。

type cType = { CustomerID: string, ContactName: string, CustomerName: string };
export const data: Object[] = orderData.map((item: object) => {
let name: cType = (<cType[]>customerData).filter((cItem: cType) => {
return cItem.CustomerID === (item as cType).CustomerID;
})[0];
(item as cType).CustomerName = (name || <cType>{}).ContactName;
return item;
});

示例:https://www.syncfusion.com/downloads/support/directtrac/general/ze/my - app - 516701544. - zip

最新更新