Skip to content

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

Merged
KevinVandy merged 3 commits intoTanStack:mainfrom
slhsxcmy:type
Mar 28, 2024
Merged

fix(table-core): narrow types for columns created by ColumnHelper#5424
KevinVandy merged 3 commits intoTanStack:mainfrom
slhsxcmy:type

Conversation

@slhsxcmy
Copy link
Contributor

@slhsxcmy slhsxcmy commented Mar 20, 2024

Fixes #5423

Updates return type of the columns created by

  • ColumnHelper.accessor to AccessorFnColumnDef or AccessorKeyColumnDef
  • ColumnHelper.display to DisplayColumnDef
  • ColumnHelper.group to GroupColumnDef
Screenshot 2024-03-19 at 7 34 38 PM

@nx-cloud
Copy link

nx-cloud bot commented Mar 20, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 6976965. 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

Sent with 💌 from NxCloud.

@KevinVandy KevinVandy merged commit 84a3513 into TanStack:main Mar 28, 2024
@edgrgomes
Copy link

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
Copy link
Contributor Author

slhsxcmy commented Apr 3, 2024

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

AccessorKeyColumnDef has accessorKey but ColumnDef doesn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants