-
-
Notifications
You must be signed in to change notification settings - Fork 48
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom useQuery typing #260
Comments
Hello! I also faced the same problem in my project. The only way I've been able to get around this problem is to use an explicit cast on the result of calling the
In runtime, this code works properly, that is, the problem is precisely in the type declarations. By the way, the problem is reproduced not only on the latest version of |
I would assume that this is due to additional overloads, that were added to accommodate for Ideally your custom hooks should not allow for all the options possible, but only those which might be needed to be changed for this particular query. |
You might want to check the following release, which might fix your problem: https://github.com/TanStack/query/releases/tag/v4.18.1 |
The last update of the library allowed me to get rid of the ugly type casts and
If I remove explicit type declaration from
|
Do you by any chance have a type annotation somewhere around this code as |
@DamianOsipiuk, I prepared a repo with a minimal reproduction of the problem I wrote about above. Repo Link: https://github.com/Alexis2004/vue-query-typings-issue Everything in this example works as it should, except for the fact that I have to explicitly type the |
@Alexis2004 I have looked at your example, basically when you use |
@DamianOsipiuk, thanks for the advice! |
Glad that it worked! 馃帀 |
Hello 馃憢
I'm trying to build some reusable useQuery functions so that I don't have to declare them every time I want to use them. To do so, and to avoid having a lot of type repetition I've also created some custom typing so that I don't need to declare the
TError
type all the time.To build my custom typing, I just tried to replicate the usage of types of
useQuery
in this codebase. It is defined as if follows:and one example of its usage in a custom useQuery:
This approach is working with
vue-query@1.25.0
but failing with@tanstack/vue-query@4.12.0
, causing the following error:The issue seems to be around the
QueryObserverResult
generic types, but I couldn't find a reason for it to not work. Am I missing something in my custom type definition or is it an issue with the types themselves?Thanks!
The text was updated successfully, but these errors were encountered: