trpc / trpc

πŸ§™β€β™€οΈ Move Fast and Break Nothing. End-to-end typesafe APIs made easy.
https://tRPC.io
MIT License
34.97k stars 1.25k forks source link

bug: useSuspenseInfiniteQuery's select method expects wrong return type #6195

Open harrytranimpt opened 5 days ago

harrytranimpt commented 5 days ago

Provide environment information

  System:
    OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics
    Memory: 392.87 MB / 3.83 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.config/nvm/versions/node/v20.16.0/bin/node
    Yarn: 1.22.22 - ~/.config/nvm/versions/node/v20.16.0/bin/yarn
    npm: 10.8.2 - ~/.config/nvm/versions/node/v20.16.0/bin/npm
    pnpm: 9.7.0 - ~/.config/nvm/versions/node/v20.16.0/bin/pnpm
  npmPackages:
    @tanstack/react-query: ^5.59.19 => 5.59.19 
    @trpc/client: 11.0.0-rc.608 => 11.0.0-rc.608+f75de97b3 
    @trpc/react-query: 11.0.0-rc.608 => 11.0.0-rc.608+f75de97b3 
    @trpc/server: 11.0.0-rc.608 => 11.0.0-rc.608+f75de97b3 
    next: 15.0.2 => 15.0.2 
    react: 19.0.0-rc-77b637d6-20241016 => 19.0.0-rc-77b637d6-20241016 
    typescript: ^5.6.3 => 5.6.3 

Describe the bug

useSuspenseInfiniteQuery does not allow a custom select method's return type. It works with useInfiniteQuery.

  const result = trpc.greeting.useSuspenseInfiniteQuery(
    {},
    {
      getNextPageParam: (p) => p.nextCursor,
      select: (data) => 1,  // Type 'number' is not assignable to type '{ pages: { text: string; nextCursor: number; }[]; pageParams: (number | null | undefined)[]; }'.
    }
  );

It works with useInfiniteQuery:

  const result2 = trpc.greeting.useInfiniteQuery(
    {},
    {
      getNextPageParam: (p) => p.nextCursor,
      select: (data) => 1, // No error
    }
  );

Link to reproduction

https://stackblitz.com/edit/github-t3rzii?file=src%2Fpages%2Findex.tsx

To reproduce

Use the select method with a useSuspenseInfiniteQuery, and return a new data

  const result = trpc.greeting.useSuspenseInfiniteQuery(
    {},
    {
      getNextPageParam: (p) => p.nextCursor,
      select: (data) => 1,  // Type 'number' is not assignable to type '{ pages: { text: string; nextCursor: number; }[]; pageParams: (number | null | undefined)[]; }'.
    }
  );

Additional information

No response

πŸ‘¨β€πŸ‘§β€πŸ‘¦ Contributing

Funding

Fund with Polar

juliusmarminge commented 5 days ago

My guess would be that this broke due to the type changes in this RQ PR: https://github.com/TanStack/query/pull/8082. Can take a look later