-
-
Notifications
You must be signed in to change notification settings - Fork 341
Type 'bigint' is not assignable to type 'Key | null | undefined' when trying to use virtualItem.key as react component key #971
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
Comments
This issue occurred when the #814 was merged. However, the react adapter still states that it supports react versions from 16, 17 virtual/packages/react-virtual/package.json Lines 68 to 70 in c325326
The actions the author can take might include 1. upgrading the React version or 2. downgrading the tanstack/virtual version. I think there are two ways to solve a more fundamental problem.
I think option 2 is appropriate since option 1 is destructive. |
What did you think about the 3 options I proposed for making it compatible?
Other than this one issue with the types, there are no issues using this library with React 17, so I will not downgrade the version of react-virtual. And I'm blocked on upgrading React for now because this is in an app that is mounted as a remote component using module federation, and I'm waiting for the host app to upgrade React. |
@akinnee First of all, thank you for the good comments. Looking at the first and third comments, I think it is appropriate to keep the previous version compatibility and at the same time solve the problem of react. If you look at the following issue #819 , this is not just a problem of React. Therefore, I think it is appropriate to solve the problem of core, not adapter, to solve this problem. I'm sorry, I didn't understand the second opinion |
Hey! @akinnee thanks for laying out the options, I was actually thinking along the same lines. After looking into it more, it seems like the only reliable fix for the type issue is to explicitly pass the key type to useVirtualizer. Inferring the key type from getItemKey alone runs into TypeScript’s generic constraint issues (TKey could be something wider), so the generic parameter is really the only way to make it work Also worth noting: if we go with the generic + default param approach (e.g. TKey extends Key = Key), this change won’t be breaking. Current users wouldn’t have to change anything. I’ll try to work on this soon-ish. 👍 Thanks |
Awesome! I'd be happy with the solution of passing in TKey. Thanks. 😁 |
Describe the bug
results in:
I suspect this may be due to being on an older version of React than what the Key type is targeting? But I don't think this should matter.
const key = String(virtualItem.key);
works fine as a workaround, but it'd be nice if either:Key
type from installed version of React is usedKey
type is inferred fromgetItemKey
Key
type could be passed to useVirtualizer, likeuseVirtualizer<TItemKey>(...)
As always, great job with this library. I love it! ❤
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-virtual-pksf2gfh?file=src%2Fmain.tsx
Steps to reproduce
key={virtualRow.key}
and see the type errorExpected behavior
Shouldn't get a type error
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
tanstack-virtual version
@tanstack/[email protected]
TypeScript version
4.9.5
Additional context
No response
Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: