【发布时间】:2021-12-11 04:46:14
【问题描述】:
我正在使用SyncFusion Grid,并为特定列定义了valueAccessor,如下所示:
export interface GridColumn<idT> {
...
valueAccessor?: (
field: string,
data: GridData<idT>,
column: Column
) => ValueAccessor | string;
}
这是列定义:
{
field: 'decimalCount',
headerText: 'Decimals',
textAlign: GridTextAlign.Center,
headerTextAlign: GridTextAlign.Center,
width: 50,
editType: GridEditType.NumericTextBox,
valueAccessor: (
field: string,
data: Partial<CustomDataGridData>
): string => data[field] ?? 'N/A',
}
但我收到以下错误
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Partial<CustomDataGridData>'.
No index signature with a parameter of type 'string' was found on type 'Partial<CustomDataGridData>'.
在html 文件中,valueAccessor 的应用如下:
<e-column
...
[valueAccessor]="column.valueAccessor ?? null"
>
我已设法通过将 data 对象转换为 any => (data as any)[field] ?? 'N/A' 来解决此问题,并且一切正常,但我无法理解原因。
【问题讨论】:
标签: typescript syncfusion ej2-syncfusion