TanStackT
TanStack16mo ago
1 reply
distinguished-brown

Tips on typing ColumnDef for a table with expandable rows

Hey folks - I'm currently implementing a table with expandable rows and looking to see if anyone has a decent pattern for typescript. Basically, my parent rows have a type of Parent and the child rows Parent['children'][number]. They will both display their name in the name column but each type uses a different key for that data. Also, most of the columns will be dedicated to child row data.

Unfortunately, typing the columns like ColumnDef<Parent> results in TS assuming every row implements the Parent type. Does anyone have a good idea for this besides massaging the data and using a discriminated union?
Was this page helpful?