-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Describe the bug
Before #2047 being merged, I used to type useQuery with just useQuery<DataType, ErrorType> to cast the error from axios. After the merge, all my typed hooks broke because if I don't type all the 4 type parameters, Typescript is inferring the second parameter as the options object instead of the function, thus throwing a Type error, as shown by the screenshot[1].
It also broke the way I typed the queries object for useQueries, as I need now to type all 4 type parameters of each array object. It was easy and very handy to use the UseQueryOptions type for the auto complete, but now it's pretty unusable if I don't type all my queries types, and if it's a lot of objects with different types, it get's very verbose (screenshot[2]).
To Reproduce
Steps to reproduce the behavior:
- Install latest version.
- Only provide the two first parameters to useQuery generic and Typescript will complain about the query function not being typed correctly.
- Install react-query version 3.12.2
- Typescript will stop complaining.
Expected behavior
Typescript should infer the second parameter of useQuery as the query function even if only two parameters are provided to the type generics, but a different issue happens with the useQueryOptions, so I think the QueryKey inferring introduced by #2047 may have brought a more in depth issue.
Screenshots

