T
TanStack2y ago
relaxed-coral

accessor function returning number gives Typescript error

The weight is a number, If I have this column:
internalSchemaClassesColumnHelper.accessor("weight", {
id: 'weight',
header: 'Weight',
cell: (info) => info.getValue()
}),
internalSchemaClassesColumnHelper.accessor("weight", {
id: 'weight',
header: 'Weight',
cell: (info) => info.getValue()
}),
It would give a long TS error on the Table comoponent:
Type 'ColumnDefBase<Class, number> & StringHeaderIdentifier' is not assignable to type 'AccessorFnColumnDefBase<Class, string> & IdIdentifier<Class, string>'.
Property 'accessorFn' is missing in type 'ColumnDefBase<Class, number> & StringHeaderIdentifier' but required in type 'AccessorFnColumnDefBase<Class, string>'.
Type 'ColumnDefBase<Class, number> & StringHeaderIdentifier' is not assignable to type 'AccessorFnColumnDefBase<Class, string> & IdIdentifier<Class, string>'.
Property 'accessorFn' is missing in type 'ColumnDefBase<Class, number> & StringHeaderIdentifier' but required in type 'AccessorFnColumnDefBase<Class, string>'.
The error goes away if I change the first argument of accessor from "weight" to (row) => row.weight.toLocaleString() The question: Should the accessor function always return string?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?