I am getting a TypeError of Type 'AccessorKeyColumnDef<Reservation, number>' is not assignable to type 'ColumnDef<Reservation>'
while trying to create a column in @tanstack/react-table
.
Here is my code:
type Reservation ={
id: number
shift: string
quantity: number
}
const columnHelper = createColumnHelper<Reservation>()
// This is the area where the error comes up, when defining columns
const columns = useMemo<ColumnDef<Reservation>[]>(
() => [
columnHelper.accessor('id', {
header: () => 'S/N',
cell: info => info.getValue(),
}),
columnHelper.accessor('shift', {
header: 'Shift',
}),
columnHelper.accessor('quantity', {
header: () => 'Quantity',
cell: info => info.renderValue(),
}),
],
[],
)
This what my data looks like
export const data = [
{
id: 1,
shift: 'BREAKFAST',
quantity: 1,
}
...
]
This is the full error
Type 'AccessorKeyColumnDef<Reservation, number>' is not assignable to type 'ColumnDef<Reservation>'.
Type 'AccessorKeyColumnDefBase<Reservation, number> & Partial<StringHeaderIdentifier>' is not assignable to type 'ColumnDef<Reservation>'.
Type 'AccessorKeyColumnDefBase<Reservation, number> & Partial<StringHeaderIdentifier>' is not assignable to type 'AccessorKeyColumnDefBase<Reservation, unknown> & Partial<IdIdentifier<Reservation, unknown>>'.
Type 'AccessorKeyColumnDefBase<Reservation, number> & Partial<StringHeaderIdentifier>' is not assignable to type 'AccessorKeyColumnDefBase<Reservation, unknown>'.
Types of property 'footer' are incompatible.
Type 'ColumnDefTemplate<HeaderContext<Reservation, number>> | undefined' is not assignable to type 'ColumnDefTemplate<HeaderContext<Reservation, unknown>> | undefined'.
Type '(props: HeaderContext<Reservation, number>) => any' is not assignable to type 'ColumnDefTemplate<HeaderContext<Reservation, unknown>> | undefined'.
I’ve tried several types but none seems to work and I think this is happening because the cell value returned for each columnHelper.accessor
has a varying type like number
and string
.
"@tanstack/react-table": "^8.20.1"
"typescript": "^5"