Skip to content

[ts] how to avoid non-null assertion with dependent queries #2281

Answered by TkDodo
stefanprobst asked this question in Q&A
Discussion options

You must be logged in to vote

As it so happens, I just wrote about this: https://tkdodo.eu/blog/react-query-and-type-script

tl;dr: one way is to keep the id undefined when passing it to the queryFn, and handling it there by rejecting the Promise. It's a bit safer because you can bypass the enabled flag, e.g. with the refetch function.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@stefanprobst
Comment options

@tianhuil
Comment options

@netanel-haber
Comment options

@netanel-haber
Comment options

Answer selected by stefanprobst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants