-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
TypeScript thinks that accessorKey is not an accessible property when column is defined with createColumnHelper #4423
Comments
any updates on this issue |
Same problem here |
My project is purely typescript basis.. I am unable to use the new version of react table. we are using old version react-table but for some features we want to upgrade it ... |
+1 Same issue here const [columnVisibility, setColumnVisibility] = useState(
columns.map((column) => ({ [column.accessorKey]: true }))
);
|
The intent with this is that you are supposed to access the |
We're trying to wrap our column Definitions into a wrapper that creates a translated title for the columns based on the resource the table is holding. I don't want to pass the resource all the way through to the table instance, so we thought we just run the column definitions that we created through a mapping function. In this case it would be sufficient to have the accessorKey as an optional type, but with it being absent the typechecking fails. |
Actually it looks like a bug because #4754 Idea to add |
This is not current behaviour. When I console log |
Did you guys come up with a solution? In my case, when I access some of my columns, such as "column.name," it gets converted to "column_name" by the id field. However, I need to access "column.name" because I need to perform some calculations based on it. |
@tushar-rupani I just ended up using meta field. |
I just tried using |
Quick Update: Thank you for your help, I was able to solve this using Meta. (: |
Using version of 8.5.13 which is not throwing any errors |
I'm using 8.9.4 and the issue remains still. |
This should be available as an optional field. The data is there. |
@KevinVandy can you pay attention to this and #4754? |
@KevinVandy I'm having this issue also. I have a scenario now where i require user defined columns, but also need to persist the column order and allow the user to rename the column. if you use the accessor only, and the user renames the column, the order gets destroyed because a column of that name no longer exists. To get it working, on column creation I assign GUID as the ID to each column, that way the GUID persists and its always unique. This also allows the user to copy columns and generate a scenario where 2 columns can have the same name. So everything works except for warning: adding the accessor key as an optional type per above would fix this issue. |
has anyone found a fix for this? @ScripterSugar @KevinVandy @xkomiks. still an annoying issue.. |
@slhsxcmy I'm using v8.16.0 and the issue still persists. |
This was fixed only for when you accessing the column inside the column helper column defs. In other places, you shouldn't try to access accessorKey. Just use the column |
I'm on version 8.20.5 and the id column does not have values copied over from the accessoryKey as @KevinVandy had indicated. The id is undefined if it is not specified in the ColumnDef. The accessorKey Typescript error still persists. My current workaround for this is column.id || column["accessorKey" as keyof typeof column] |
Share a sandbox of the I'd not being initialized correctly from the accessorKey |
@KevinVandy I found the problem for the Typescript error. The code was originally written for version 8.9.2. But the id not copying over still persists. |
Not sure if this is related but this issue has started happening for me. Here's an example:
This seems like an error, especially since |
@KevinVandy can confirm, this advice is a bit outlandish when
if I log columns 2 things are generated |
Describe the bug
When I describe columnDefs via the
createColumnHelper
api, TypeScript informs me thataccessorKey
is unavailable. But when I console log the contents of the defined columns,accessorKey
is very clearly available.Your minimal, reproducible example
https://codesandbox.io/s/tanstack-react-table-accessorkey-issue-v68163
Steps to reproduce
Expected behavior
As a user, I expect to be able to access
accessorKey
without typescript issues when defining my columns via thecreateColumnHelper
API, but typescript doesn't think the field exists or is availableHow often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
react-table version
8.5.15
TypeScript version
4.8.3
Additional context
No response
Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: