Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 28, 2024

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

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
2 checks passed
@edgarbagagem
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