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
useful-bronze•2y ago
huh, where in the docs?
absent-sapphireOP•2y ago
absent-sapphireOP•2y ago
The stuff in the const
useful-bronze•2y ago
Why is it not available to define in my code?no clue what you mean
absent-sapphireOP•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) =&...
absent-sapphireOP•2y ago
I am just trying to do: const queryResult : insertUseQueryReturnTypeHere = useQuery(...
deep-jade•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.
absent-sapphireOP•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?

useful-bronze•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 senseabsent-sapphireOP•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.

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