Skip to content
Discussion options

You must be logged in to vote

Hi @beingbook! The discriminated unions have been dropped because they add quite a bit of types and some complexity while in my opinion, not bringing much value:

// A common pattern is to destructure the query result, but in doing so, the unions would have no effect:
const { error, data } = useQuery()

// In case someone did use the status property to discriminate:
const result = useQuery()

if (result.status === 'idle') {
  // Don't need to assert `data` and `error`
}

if (result.status === 'loading') {
  // Still need to assert `data` or `error`
}

if (result.status === 'error') {
  // Still need to assert `error`, because technically it could be anything
}

if (result.status === 'success'

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ellemedit
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants