T
TanStack11mo ago
conscious-sapphire

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?
1 Reply
conscious-sapphire
conscious-sapphireOP11mo ago
I think I might have just rubber duckied this... the discriminated union seems to work well enough with a typeguard. Would still be interested to hear if anyone uses a different approach.

Did you find this page helpful?