T
TanStack2y ago
sensitive-blue

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
quickest-silver2y ago
huh, where in the docs?
sensitive-blue
sensitive-blueOP2y ago
The stuff in the const
quickest-silver
quickest-silver2y ago
Why is it not available to define in my code?
no clue what you mean
sensitive-blue
sensitive-blueOP2y 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-blue
sensitive-blueOP2y ago
I am just trying to do: const queryResult : insertUseQueryReturnTypeHere = useQuery(...
conscious-sapphire
conscious-sapphire2y 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-blue
sensitive-blueOP2y 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?
No description
quickest-silver
quickest-silver2y 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 sense
sensitive-blue
sensitive-blueOP2y 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.
No description
sensitive-blue
sensitive-blueOP2y ago
And indeed... I had to insert moduleResolution: "node", somewhere in my convoluted nx/vite setup... now it works. Thank you everyone!

Did you find this page helpful?