Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Type 'bigint' is not assignable to type 'Key | null | undefined' when trying to use virtualItem.key as react component key

Aberta
#971 5 comentários 8 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@restareaByWeezy já está trabalhando nisso.

Desde 7/3/2026.

  • #1140 de @restareaByWeezy — aberto

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:

  • Key type from installed version of React is used
  • Key type is inferred from getItemKey
  • Key type could be passed to useVirtualizer, like useVirtualizer<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

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TanStack/virtual

Todas as issues de TanStack/virtual

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.