TanStack Table dynamically passed generic types - setting generic key type for createDataColumn? #4054
Unanswered
nickduan-pcln
asked this question in
Q&A
Replies: 5 comments 1 reply
-
I also try to create pretty much the same way and I also get errors ( |
Beta Was this translation helpful? Give feedback.
0 replies
-
I also have the same problem by trying to implement a generic table |
Beta Was this translation helpful? Give feedback.
1 reply
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Any update on this, I'm still facing this issue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi team,
I'm trying to create a generic table which takes in multiple different object types with different object keys, from different parts of my repo. I've been able to implement this table and have it render with the different object types, but I'm unable to get the typing correct for the


createDataColumn()
key parameter to stop TypeScript from complaining.I'm setting the table row type like so:
const table = createTable().setRowType<T>()
to take in generic types, and as a result, I'm getting the errorArgument of type 'string' is not assignable to parameter of type 'keyof T | AccessorFn<T>'
(string type being that of the key).For some background on the data being received by the table, I'm passing an array of objects of different types and sizes and based on the documentation, the
createDataColumn()
function takes in and maps the keys of the object to the data column. Thus I'm extracting just the first object and using its keys to map all the columns. This way of handling the keys effects turns them into typestring
and creates the conflict with the table row expecting akeyof T
type (as specified insetRowType<T>()
.The way I've tried to mitigate this issue is by setting my object keys as

keyof T
types in the initial extraction process:const cols = Object.keys(data[0]) ==> const cols = Object.keys(data[0]) as Array<keyof T>
. However, when this happens, I'm faced with a different error in the form of:This is in essence what I would like to implement:
Examples of TanStack component being called:
So I'm wondering if there might be another simple way of fixing my typing issue or if there is some overhead that I need to implement myself?
Any help would be much appreciated!
Thanks 🙏
Beta Was this translation helpful? Give feedback.
All reactions