Skip to content
Discussion options

You must be logged in to vote

I think that's because data is part of the large discriminated union type. If you add data unconditionally, the type needs to be a QueryObserverSuccessResult. So you'd also have to set status and derived booleans accordingly.

That is insanely unnecessary 😅 , but it would look something like this (ported to v4): https://codesandbox.io/s/thirsty-wescoff-vhxbw7?file=/src/App.tsx:523-802

The easiest thing to do is to just remove the return type annotation from your custom hook and let typescript infer the complex union type.

also, depending on what you'd like to transform, the select option might be better suited.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lisherwin
Comment options

@TkDodo
Comment options

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