Typescript: how can I assert the type of a variable derived from the data returned from a query if isSuccess
is true?
#8789
Replies: 1 comment 1 reply
-
we have a discriminated union type internally, but that discrimination gets lost when you just create your own object. Not sure what your use-case is but the simple version is likely just:
|
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.
-
React-Query can tell Typescript that the result of a query is defined if the
isSuccess
flag is true (withDefinedUseInfiniteQueryResult
), but I can't figure out how to tell Typescript to do the same for a value derived from the query results such as the following.This will yield
'derived' is possibly 'undefined'.ts(18048)
and I'm not really sure how React-Query does the trick with the original query result in the first place.Can I express that a derived values is defined if it is dervied from the query result and
isSuccess
is true without additional null checks?Beta Was this translation helpful? Give feedback.
All reactions