vercel / vercel/swr

useSWRInfinite has missing types

Open
#3,003 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
32.5k
Forks
1.4k
Avg merge
28m
Merged PRs (30d)
2

Description

Bug report

When you use useSWRInfinite with pagination based on cursor, getKey callback has type any for previousPageData

Description / Observed Behavior

image

Expected Behavior

To be correct type same as return type from fetcher

Repro Steps / Code Example

Or share your code snippet or a CodeSandbox link is also appreciated!

Additional Context

SWR version.
v2.2.5

Add any other context about the problem here.

Contributor guide

Open the contributing guide

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.

Research direction

Start at the useSWRInfinite entry point and inspect the getKey callback type for previousPageData alongside the fetcher return type. Confirm the expected behavior with a typed cursor-pagination example. Done means previousPageData is inferred as the fetcher’s return type rather than any.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.