typescript - 'children' özelliği 'ColDef
AG Grid üzerinde bir proje yapmaya çalışıyorum ama TypeScript ile ilgili bir hata ile karşılaşıyorum. Hata şunu söylüyor ([AG-Grid] 'children' özelliği 'ColDef' türünde mevcut değil) ve aşağıdaki filter yöntemi etrafında (column => column.children) bu hatayı alıyorum.
Ag-grid belgelerine gittim ama sütun tanımları (column defs) özellik olarak children kullanmayı destekliyor. Bu yüzden neden bu hatayı aldığımı anlamıyorum.
import { ColDef, ColGroupDef } from 'ag-grid-community';
export const sampleItems: Array<{
label: string;
value: string;
}> = [];
export const TABLE_COLUMN = [
{
headerName: 'User',
children: [
{
field: 'user',
headerName: 'Name',
pinned: 'left',
type: 'fixed',
},
{ field: 'account', pinned: 'left', type: 'fixed' },
{
field: 'price',
headerName: 'Pricing',
pinned: 'left',
type: 'primary',
},
],
},
{
headerName: 'Address',
children: [
{ field: 'address', headerName: 'Address', type: 'secondary' },
{
field: 'street',
headerName: 'Street Name',
columnGroupShow: 'closed',
type: 'secondary',
},
],
},
] as (ColDef<object> | ColGroupDef<object>)[];
TABLE_COLUMN.filter((column) => column.children != null).forEach(
(column) => {
column.children.forEach((child) => {
if (child.type === 'fixed' || child.type === 'primary') {
sampleItems.push({
label:
child.headerName ??
child.field.charAt(0).toUpperCase() + child.field.slice(1),
value: child.field,
});
}
});
},
);
Cevap #1
Mantığı şu şekilde değiştirin. TypeScript'e bunun bir colGroupDef olacağını söylüyoruz, bu yüzden ColDef türünü kontrol etmekle uğraşmayacak.
(<ColGroupDef<object>>TABLE_COLUMN).filter((column: ColGroupDef<object>) => column.children != null).forEach(
(column: ColGroupDef<object>) => {
column.children.forEach((child: ColDef<object>) => {
if (child.type === 'fixed' || child.type === 'primary') {
sampleItems.push({
label:
child.headerName ??
child.field.charAt(0).toUpperCase() + child.field.slice(1),
value: child.field,
});
}
});
},
);
