Skip to content
Source
Sign inSign up
TanStack/query

v5: infiniteQuery incorrectly infers unknown as data when used with select #5881

Send to my agent
Closedcs-clarence(GitHub profile, opens in a new tab) opened this issue 10 comments

Describe the bug

createInfiniteQuery infers unknown for QueryFnData

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/nostalgic-matan-nrdklh

Steps to reproduce

  1. use createInfiniteQuery
  2. Provide the required fields for the query options
  3. The inferred query data for the pages is unknown[]

Expected behavior

createInfiniteQuery to infer querFn return type as the query data type

How often does this bug happen?

Always

Screenshots or Videos

No response

Platform

-OS: Linux

Tanstack Query adapter

solid-query

TanStack Query version

v5

TypeScript version

v5.1.6

Additional context

No response

  1. Possibly related issue: infiniteQueryOptions in react-query also seems to incorrectly infer the data type without the InfiniteData wrapper, which provides the individual pages.

  2. you are right, it seems to be a general issue with select on infinite queries. Here is a typescript playground showing the same issue for react.

    @ecyrbe could you maybe take a look at this?

  3. TkDodo changed the title

  4. TkDodo added labelsbug

  5. TkDodo added labelshelp wanted

  6. TkDodo added labelstypes

  7. TkDodo added labelspackage: query-core

  8. @TkDodo on it, did something change since we added the feature ? i remember we added type checking tests for this. Any regression should have been caught.

  9. @ecyrbe I'm not sure, but we certainly haven't deleted any tests. So I think we probably don't have a test for this case.

  10. I also noticed that it is the same case with createQuery. Specifying select breaks the inference

    I added it on the codesandbox here. It's on line 19.

    Here it is used with useQuery in react-query.

    getNextPageParam page arguments (first and second) are also unknown in useInfiniteQuery as seen here

  11. @TkDodo on my side, all type tests are broken. i don't know how they are passing in CI/CD. Something broke the whole thing. i'm not sure where this regression came from. still on it.

  12. @TkDodo ok i found the origin of the issue, it was a change made 3 weeks ago to remove suspense from the resulting infinitte query options, just ordering the Omit properly like this fixes the issue : image

  13. There is still an issue with the type tests as they are ignored by ci/cd. i guess it's because typeschecking is disabled in tests. i strongly suggest to get it back. else these kind of regressions will get incognito into someones production.

  14. @lachlancollins can you take a look why the tests are excluded from type checks in ci/cd? My guess is because we only use tsc now to produce d.ts output, and tests are not included? However, we should really have a check where all typescript files are checked for correctness.

  15. TkDodo closed this

  16. There is still an issue with the type tests as they are ignored by ci/cd

    @ecyrbe I've investigated this a bit more. If I revert your change, all type tests pass. If I change something inside one of the type tests, it is correctly reported as failure. Could it be that we just didn't have a test for this case? I think there's nothing wrong with our CI setup ...

Sign in to join this conversation.