Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#971 5 comentarios 8 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
react, typescript
Área
frontend

Línea de trabajo

Comienza con la declaración de tipo generada en index.d.ts, línea 98, y reproduce el error en main.tsx del ejemplo enlazado de StackBlitz. Compara el tipo expuesto de virtualItem.key con el tipo de key de React usando TypeScript 4.9.5; se considera hecho cuando key={virtualItem.key} pasa la comprobación de tipos sin requerir el workaround de String.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
7.1k
Forks
468
Merge medio
1 d 2 h
PR fusionados (30 d)
12

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/virtual

Todos los issues de TanStack/virtual

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.