Why no TS useQuery type?
Hello,
In the useQuery docs, there is a pretty explicit return data object definition (data, dataUpdatedAt, error, errorUpdatedAt, failureCount, etc...). Why is it not available to define in my code? (I keep reading complicated stuff about generics)...
11 Replies
quickest-silver•2y ago
huh, where in the docs?
sensitive-blueOP•2y ago
sensitive-blueOP•2y ago
The stuff in the const
quickest-silver•2y ago
Why is it not available to define in my code?no clue what you mean
sensitive-blueOP•2y ago
My IDE (phpStorm) does not automatically detect the return type from useQuery (it usually does for other libraries) . I've searched online and I get "complicated" answers such as this one... https://stackoverflow.com/questions/74169668/typescript-usequery-type
Stack Overflow
Typescript useQuery Type
What would be the type which I have defined as any? I have tried TQueryFnData as per the RQ docs. but get Cannot find name 'TQueryFnData'
export const useFetchUser = (userID: string | undefined) =&...
sensitive-blueOP•2y ago
I am just trying to do: const queryResult : insertUseQueryReturnTypeHere = useQuery(...
conscious-sapphire•2y ago
This is because probably because your async function doesn’t have a return type defined.
You should tell typescript what the response data looks like like in the example.
sensitive-blueOP•2y ago
This is where my problem is... in the return type of useQuery itself. I suppose I have to manually define the default useQuery return object?

quickest-silver•2y ago
still no clue what you talk about.
useQueryResult
will have a data
property and an error
property and status
and everything ...
please show a codeasandbox or a typescript playground, otherwise this makes no sensesensitive-blueOP•2y ago
The IDE reports as "any". It's probably a misconfiguration on my setup... I will do some research and come back go you guys. Thank you very much for your time.

sensitive-blueOP•2y ago
And indeed... I had to insert moduleResolution: "node", somewhere in my convoluted nx/vite setup... now it works. Thank you everyone!