Replies: 1 comment 1 reply
-
TypeScript can't know that, and technically, typescript is right. You could e.g. still invoke I have a short paragraph on this in my TypeScript blog: https://tkdodo.eu/blog/react-query-and-type-script#type-safety-with-the-enabled-option |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to write a custom hook for a dependent query but I get the following type error when calling
testQueryFunction(params)
. Error:Argument of type 'number | null' is not assignable to parameter of type 'number'.
Custom Hook:
Based on this discussion I'd expect the above to work but typescript doesn't understand that the queryFn will only be called when
params
is defined. I tried changing the example code to makeparams
the data of another query to more closely match the example and I still get the same type error.What is the proper way to type this without requiring
testQueryFn
to acceptnull
arguments?Beta Was this translation helpful? Give feedback.
All reactions