Type 'bigint' is not assignable to type 'Key | null | undefined' when trying to use virtualItem.key as react component key
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 45/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- react, typescript
- Domínio
- frontend
Direção de pesquisa
Comece com a declaração de tipo gerada na linha 98 de index.d.ts e reproduza o erro em main.tsx no exemplo vinculado do StackBlitz. Compare o tipo exposto de virtualItem.key com o tipo de key do React no TypeScript 4.9.5; está concluído quando key={virtualItem.key} passa na verificação de tipos sem exigir o workaround de String.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Describe the bug
<SomeItem key={virtualItem.key} />
results in:
Type 'Key' is not assignable to type 'Key | null | undefined'.
Type 'bigint' is not assignable to type 'Key | null | undefined'.ts(2322)
index.d.ts(98, 9): The expected type comes from property 'key' which is declared here on type 'IntrinsicAttributes'
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:
Keytype from installed version of React is usedKeytype is inferred fromgetItemKeyKeytype 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
- Open StackBlitz link
- In main.tsx, scroll down to
key={virtualRow.key}and see the type error
Expected behavior
Shouldn't get a type error
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- MacOS 14.4
- VSCode 1.98.2
- TypeScript 4.9.5
tanstack-virtual version
@tanstack/[email protected]
TypeScript version
4.9.5
Additional context
No response
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- Linguagem predominante
- TypeScript
- Estrelas
- 7.1k
- Forks
- 478
- Merge médio
- 1d 3h
- PRs com merge (30d)
- 31
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TanStack/virtual
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
Mantenedores costumam responder em até 1 dia
-
anchorTo: 'end' loses the end when the scroll element shrinksTalvez já em andamento @langleyd assumiu há 14 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
marko-virtual: scrollToEnd during an in-flight prepend strands the view one prepend above the bottom (chat-pretext e2e fails on CI)Talvez já em andamento @prayaggaikwad96 assumiu há 8 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 42/100
TanStack/virtual#1252 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
lit-virtual: VirtualizerController never applies updated options after constructionTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Aberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 45/100
Mantenedores costumam responder em até 1 dia
Todas as issues de TanStack/virtual
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
endora-commerce/endora-commerce#397 ·
Mantenedores costumam responder em até 1 dia
-
level/task
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
wazuh/wazuh-dashboard-plugins#9472 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 63/100
Mantenedores costumam responder em até 1 dia
-
ready-for-agent
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
xavxyz/bei-shan-lin-shui#57 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
opennextjs/opennextjs-cloudflare#1461 ·
Mantenedores costumam responder em até 1 dia