Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryCache's documentation of the find functions does not match its usage #5177

Closed
AaronActu opened this issue Mar 22, 2023 · 1 comment
Closed
Labels
documentation Improvements or additions to documentation

Comments

@AaronActu
Copy link

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

  1. Go to the sandbox example
  2. Uncomment where it's written to and comment the good way to do
  3. 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

@AaronActu AaronActu changed the title QueryCache's documentation about find functions does not match use QueryCache's documentation of the find functions does not match its usage Mar 22, 2023
@TkDodo
Copy link
Collaborator

TkDodo commented Mar 25, 2023

sorry for that. We've adapted the docs to how it will work in v5, where we will only pass filters to each function. Most function have overloads, like:

findAll(queryKey?: QueryKey, filters?: QueryFilters): Query[];
findAll(filters?: QueryFilters): Query[];

so both passing in the key as fist arg or filters works, and filters does have a queryKey prop. In v5, only the filters option will be valid.

The docs change was okay for all functions that had overloads, but apparently, in v4, queryCache.find doesn't have the overloads.

So, if you want, please open a PR to the docs for v4 (main branch) that reverts the change, and one for v5 (alpha branch) that re-introduces it :)

@TkDodo TkDodo added the documentation Improvements or additions to documentation label Mar 25, 2023
@TkDodo TkDodo closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants