-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Describe the bug
Hey there,
I was trying to use the QueryCache provider like it was described in the documentation.
const query = queryCache.find({ queryKey: ['posts'] })
I directly faced a typescript error :
Argument of type '{ queryKey: string[]; }' is not assignable to parameter of type 'QueryKey'.
Object literal may only specify known properties, and 'queryKey' does not exist in type 'readonly unknown[]'.ts(2345)
I did check the typescript signature of find, findAll and I found out that in fact it does not match the documentation :
find<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData>(arg1: QueryKey, arg2?: QueryFilters): Query<TQueryFnData, TError, TData> | undefined;
findAll(queryKey?: QueryKey, filters?: QueryFilters): Query[];
findAll(filters?: QueryFilters): Query[];
findAll(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): Query[];
To resolve this typescript error I had to use this instead : const query = queryCache.find(['posts'])
Also, it was not explicit that we had to add the QueryCache instance to the QueryClient in order to work properly. Check out the example in the sandbox.
Your minimal, reproducible example
https://codesandbox.io/s/react-query-cache-doc-error-gsjqw3?file=/src/App.tsx
Steps to reproduce
- Go to the sandbox example
- Uncomment where it's written to and comment the good way to do
- Enjoy the typescript error !
Expected behavior
Edit the documentation to match the actual typescript signature (or the contrary)
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Not related
Tanstack Query adapter
react-query
TanStack Query version
v4.27.0
TypeScript version
v4.4.2
Additional context
No response