Can someone please help me understand why I am encountering an error with this specific line of code:
rowData[headerKey] = value;
The error message I am getting is:
Type 'string' is not assignable to type 'never'.ts(2322) const headerKey: never
Below is the block of code in question:
const exportData = (
table.getSortedRowModel().rows.length > 0
? table.getSortedRowModel().rows // Use sorted data if available
: table.getCoreRowModel().rows
).map((row) => {
const rowData: Partial<TableDataGeneralTemp> = {};
row.getVisibleCells().forEach((cell) => {
if (cell.column.columnDef.header !== "IsSelected") {
const value = cell.getValue() as string;
const headerKey = cell.column.columnDef.header as keyof TableDataGeneralTemp;
rowData[headerKey] = value;
}
});
return rowData;
});
Here are the respective interfaces for reference:
interface TableData1 {
application_date: string;
application_id: string;
applicant_name: string;
institution?: string;
applicant_email?: string;
status: string;
payment_status: string;
}
// Other interface definitions...
interface CommonTableData {
isSelected: boolean;
}
type TableDataGeneralTemp =
| TableData1
| TableData2
| TableData3
| DocStatusData
| InvoiceData
| ReceiptData;
// More type definitions...
I attempted to resolve the error by including this check:
if (headerKey && headerKey in rowData) {
rowData[headerKey as keyof TableDataGeneralTemp] = value;
}
Unfortunately, this correction did not successfully address the issue. Previously, the function was error-free until additional code was integrated into the component. Now, I am struggling to troubleshoot and eliminate this type error.