query data type is (Type | undefined) after `isError` check
I expect
data
to be type of VisitResponse
after isError
check, but it is VisitResponse | undefined
If I do the following I get the type of VisitResponse
for data
Is there way to change this behaviour so that checking only isError
would suffice?4 Replies
wise-white•14mo ago
you haven't checked for
isPending
, so it's not guaranteed that data is therestormy-goldOP•14mo ago
So, would the following be the correct approach?
wise-white•14mo ago
if (isPending)
is enoughstormy-goldOP•14mo ago
I did not know about the change of
isLoading
to isPending
The following link is a good reference for those who might check this question.
https://tanstack.com/query/latest/docs/framework/react/guides/migrating-to-v5#status-loading-has-been-changed-to-status-pending-and-isloading-has-been-changed-to-ispending-and-isinitialloading-has-now-been-renamed-to-isloadingMigrating to TanStack Query v5 | TanStack Query React Docs
Breaking Changes
v5 is a major version, so there are some breaking changes to be aware of: