TanStack / table

🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
https://tanstack.com/table
MIT License
24.61k stars 3.04k forks source link

Columns created by columnHelper.accessor doesn't know accessorFn or accessorKey #5423

Closed slhsxcmy closed 4 months ago

slhsxcmy commented 4 months ago

TanStack Table version

8.14.0

Framework/Library version

18

Describe the bug and the steps to reproduce it

Columns created by columnHelper.accessor has type ColumnDef, which is a union of AccessorColumnDef, DisplayColumnDef, and GroupColumnDef. As a result, they don't know that the accessorFn or accessorKey property exists.

Typing them as narrower types like AccessorFnColumnDef or AccessorKeyColumnDef would allow access to these properties. This is helpful for our current use case where we want to directly call the accessorFn on fake data in unit tests.

Example at the bottom of TS Playground

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

See above

Screenshots or Videos (Optional)

Screenshot 2024-03-19 at 7 52 12 PM

Do you intend to try to help solve this bug with your own PR?

Yes, I am also opening a PR that solves the problem along side this issue

Terms & Code of Conduct