table: [v8] Type Error in ColumnDef
Describe the bug
ColumnDef typing is not working correctly, when a type is passed as a parameter it doesn’t show me the correct typing
Your minimal, reproducible example
https://codesandbox.io/s/react-typescript-forked-gr4xw1?file=/src/App.tsx
Steps to reproduce
when you fill in the accessorKey you will see that its typing is string, and it should be keyof Person
Expected behavior
should return the typing as: accessorKey: firstName | lastName | age | visits | status | progress and any other value that is entered should be returned typing error
How often does this bug happen?
Every time
Screenshots or Videos

Platform
- OS: windows
- Browser: any browser
react-table version
v8.5.11
TypeScript version
v4.6.3
Additional context
No response
Terms & Code of Conduct
- I agree to follow this project’s Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (1 by maintainers)
@mnlfischer Thanks for your response! I managed to avoid the ts errors by casting the column definition arrays as follows:
This works well with my generic
Tablecomponent for which I have typed thecolumnsanddataproperties as follows:The
Tablecomponent has the following signature:This is a very basic snapshot of how I have chosen to solve this but this works pretty well and still provides me with the required strongly typed implementation I wanted.
Hi! I’m still getting this error 😦
"@tanstack/react-table": "8.12.0","typescript": "5.2.2"Looks like problem with ColumnDef<T> still there. Here is sandbox from TanstackTable website, I am just passing columns as a prop. And the types just dont match. https://codesandbox.io/s/columndef-react-table-x1452j?file=/src/main. does anyone still has the same problem? Because I am not allowed to use any.
That did not work for me - columnHelper returns a type for a specific field of the column and not the entire column type. Example:
I’m still facing the error:
The solution proposed by @TheOftedal to cast the
TValuetounknown:doesn’t fix the problem, it just hides it by disabling types validation on the array. In fact, if I add a random element (e.g. a completely different object or even a primitive like a string) to the
columnsarray, the TypeScript compiler still considers this valid, which is not the behavior we want.The only solution that I’ve found so far is to cast the column type to
anyas @utkuturunc proposed:In particular, I’ve created a shared type helper that I can use in all the tables of my application:
so that I have to disable the
no-explicit-anyeslint rule only once.I hope this helps, but I really hope that this gets fixed or we get better guidance on how to implement types inference properly from the maintainers.
For me the main goal is to not lose the type information about cell values. To achieve this goal I found two workarounds:
First workaround:
Second workaround:
Probably at some point you will have to type cast
columnstoColumnDef<Person>[], but for me this isn’t an issue.We have a similar problem in our code.
Give me this typescript error
I can type it to
ColumnDef<Shipment, string>but then field like totalUnits which is a number gives me an error that it is not a string.@iblecher in that case
should work
What fixed the issue for me was to not export the columns from another file but use them directly there , the export keyword seems to be the culprit for me.
Works well for this case but when I have custom functionFn that returns boolean I get error: TS2322: Type “isWithinRange” is not assignable to type FilterFnOption<Verification> | undefined
Yes. Typescript limitations. We’ll be able to get around these with time.
I think
accessorKeyshould show only possible keys fromColumnDefgeneric. What is point of defining it anyways, when basic type propagation doesn’t work as expected? Is there any blocker to fix this behavior instead of using these helper functions? 🤔i’m working around this by using
Please use the createColumnHelper<Person>().accessor(options) API
Tanner Linsley On Aug 14, 2022, 5:32 PM -0600, Celso Dias @.***>, wrote:
thanks @utkuturunc but we use
@typescript-eslint/no-explicit-anyrule which doesn’t allow me to useany