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

Open
#971 5 comments 8 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@restareaByWeezy is already working on this.

Since Mar 7, 2026.

  • #1140 by @restareaByWeezy — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
react, typescript
Domain
frontend

Research direction

Start with the generated type declaration at index.d.ts line 98 and reproduce the error in main.tsx from the linked StackBlitz example. Compare the exposed virtualItem.key type with the React key type under TypeScript 4.9.5; done means key={virtualItem.key} type-checks without requiring the String workaround.

Written by the indexing model from the issue text.

Description

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.
Dominant language
TypeScript
Stars
7.2k
Forks
495
Avg merge
23h 16m
Merged PRs (30d)
19

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TanStack/virtual

All issues in TanStack/virtual

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.