TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
42.75k stars 2.92k forks source link

`infiniteQueryOptions` can't be used with both `useInfiniteQuery` and `useSuspenseInfiniteQuery` #8184

Closed alisamonstr closed 1 month ago

alisamonstr commented 1 month ago

Describe the bug

When upgrading from 5.59.9 to 5.59.14 the types from basic infiniteQueryOptions changed so they don't work with both useInfiniteQuery and useSuspenseInfiniteQuery when you set

 "compilerOptions": {
    "strict": true,
    "exactOptionalPropertyTypes": true
  }

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-xfkpkc?file=src%2FApp.tsx

Steps to reproduce

  1. Go to App.tsx
  2. Observe Type error on line 41 (infiniteQueryResult)
  3. Downgrade to "@tanstack/react-query": "5.59.9"
  4. Go back to App.tsx and observe that the Type error is gone

Expected behavior

Not having a Type error

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Tanstack Query adapter

react-query

TanStack Query version

5.59.14

TypeScript version

5.6.2

Additional context

No response

TkDodo commented 1 month ago

Do you think adding | undefined here would fix it?

https://github.com/TanStack/query/blob/a085c92a5324b049ac4fc43d58c075815a6380e4/packages/react-query/src/infiniteQueryOptions.ts#L50-L62

alvarlagerlof commented 1 month ago

Do you think adding | undefined here would fix it?

(same team) It doesn't fix it because infiniteQueryOptions still matches UnusedSkipTokenInfiniteOptions, which isn't supported by any of the useInifiniteQuery overloads. Previously, our infiniteQueryOptions used the UndefinedInitialDataInfiniteOptions type.

TkDodo commented 1 month ago

@gwansikk I think this traces back to your PR:

could you please have a look?

gwansikk commented 1 month ago

I have reviewed the example project you provided, but I couldn’t reproduce the bug you mentioned. Could you please provide more detailed information about the issue?

alvarlagerlof commented 1 month ago

I have reviewed the example project you provided, but I couldn’t reproduce the bug you mentioned. Could you please provide more detailed information about the issue?

Try adding "exactOptionalPropertyTypes": true to the tsconfig.app.json file. It seems like it it wasn't always enough to just have it in the tsconfig.json.

You should see an error like this:

Image

gwansikk commented 1 month ago

Try adding "exactOptionalPropertyTypes": true to the tsconfig.app.json file. It seems like it it wasn't always enough to just have it in the tsconfig.json.

@alvarlagerlof Thank you! I will look into finding an appropriate solution as soon as possible.

alvarlagerlof commented 1 month ago

Do you think adding | undefined here would fix it?

query/packages/react-query/src/infiniteQueryOptions.ts

Lines 50 to 62 in a085c92

& { queryFn?: Exclude< UseInfiniteQueryOptions< TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam ['queryFn'], SkipToken

}

I realize now that I misinterpreted this and didn't add the | undefined at the right place in my local edit when testing. Anyways the fix worked. Thanks everyone!