Incorrect type for `getNextPageParam` in `vue-query`'s `useInfiniteQuery` #6177
Send to my agentDescribe the bug#
When calling useInfiniteQuery, the type of the first parameter to the getNextPageParam option was previously inferred from the return type of queryFn; this is no longer the case and the type defaults to unknown.
Your minimal, reproducible example#
Steps to reproduce#
- Visit example
- See
'lastPage' is of type 'unknown'.in the Errors tab
Expected behavior#
As a user, I expected the type in the example to be Response, but the type is actually unknown.
How often does this bug happen?#
None
Screenshots or Videos#
No response
Platform#
n/a
Tanstack Query adapter#
None
TanStack Query version#
v5.0.0
TypeScript version#
v5.2.2
Additional context#
Possibly related to #6174 — this error also goes away when using react-query instead of vue-query.
TkDodo added labelsbug
TkDodo added labelstypes
TkDodo added labelspackage: vue-query
it should work with inline functions as well. The same code works if you use the react adapter:
so there's something off with the vue typings. If you want to investigate this, please go ahead. the vue-query typings are a bit different than the react ones:
Otherwise, I'll have to leave this to @DamianOsipiuk
@zqianem Your TS playground example seems to be fixed with https://github.com/TanStack/query/releases/tag/v5.0.4
Looks like issue is still there but with queryFn. queryFn doesn't see what type you return.
This seems to have regressed in react now. I'm getting the exact same issue (and https://github.com/TanStack/query/issues/6177#issuecomment-1768763417 doesn't fix it)
UPDATE: Sorry, just realised this is happening in
prefetchInfiniteQuery- will raise a new issue
Sign in to join this conversation.
Interestingly it works if you extract the query function, but not if you use it inline
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgVwM4FMCSA7AZsbYGdARWXSgE8AaOMiygMWWwGMZgJsBhL4gD3gBfOLigQQcAOQABGAENsqBawDWAegBu5ALQBHclSkBYAFBncLdp2xwA5uhiMIEABQIw8hwAV5UeSBCAFx0hkxWHFy82AIwADxQ6PIAJlwANpRwANrKUAR2ALq02MggAEYUAHwAlIhmcHCJMMhQtriOrAAWrgAGnTAwYKhB6uro-AFgaegAdKwS6gAkHl7ovv6BPdVmQmZmaFh4BESkYe71cAYMANLolCFZUrguUgVw8qhw80ow1BfHHHkaV8Pj8ARCAAY-qYGlcqIxsCEHE4XNCGsiAHLjGAgtZgkAhVxpD441a1AC8lTgRJJuJmEFUcAA-HAAIxwEIlNJpbamITVIA