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

fix(table-core): narrow types for columns created by ColumnHelper #5424

Closed slhsxcmy closed 4 months ago

slhsxcmy commented 4 months ago

Fixes https://github.com/TanStack/table/issues/5423

Updates return type of the columns created by

Screenshot 2024-03-19 at 7 34 38 PM
nx-cloud[bot] commented 4 months ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 697696557a682b23ba34209bfc006de1b51cefc0. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target - [`nx affected --targets=test:format,test:sherif,test:knip,test:lib,test:types,build --parallel=3`](https://cloud.nx.app/runs/zQOJCyQ8Hp?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.

edgarbagagem commented 4 months ago

Hello everyone,

While this works with helper.accessor({}).accessorKey, it doesn't seem to work for something like this

const columns: ColumnDef<T>[] = [
helper.accessor('example' ,{ example})
...
]

columns.map(c => c.accessorKey)

Error:
Property 'accessorKey' does not exist on type 'ColumnDef<TData>'.
Property 'accessorKey' does not exist on type 'ColumnDefBase<TData, unknown> & StringHeaderIdentifier'.

My use case here is that I pass columns as props for a wrapper component of the table and I have some options where I need to access the accessorKey of the columns

Sorry for bad english

slhsxcmy commented 3 months ago

@edgarbagagem try typing the columns AccessorKeyColumnDef<T>[] or leave out the type to let Typescript infer

AccessorKeyColumnDef has accessorKey but ColumnDef doesn't