Typings of useQuery({ throwOnError:true }).data
should not depend on query.isError
#6805
Unanswered
AriPerkkio
asked this question in
Ideas
Replies: 2 comments 2 replies
-
This would be great to have and I think quite easy to change typings for. Problem is that you'd need to need one overload for each combination of options that affect the return type in useQuery.ts. Would a PR for this be considered? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Any updates on that ? this would improve greatly dx |
Beta Was this translation helpful? Give feedback.
2 replies
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.
-
This is a feature request to improve return type of
useQuery
whenthrowOnError
is set totrue
.Reproduction: https://stackblitz.com/edit/vitejs-vite-pg39ou?file=src%2FApp.tsx
Relevant code:
Typings of the return type require checking for
.isError
even though that property should never be used. The function call ofuseQuery
throws the error instead of adding it into return value.I would expect this to pass typechecking:
But the
query.data
is nullable as.isError
has not been checked for narrowing down the type.As
throwOnError
can also be function that returnsboolean
, this improvement can only be used whenthrowOnError
is set totrue
explicitly.As work-around for now I think I'll be using following:
Beta Was this translation helpful? Give feedback.
All reactions