Skip to content
Discussion options

You must be logged in to vote

Question: why does the signature enforce widening to T | undefined?

simple scenario: A query can be in error state and you can still call setQueryData on that query. In those cases, you will be handed undefined, that's why the types reflect that.

The real problem is that you cannot return undefined. In v4, we've adapted the functionality and the typings are now:

 updater: Updater<TData | undefined, TData | undefined>, 

so if you get undefined, you can just return undefined to bail out of state updates:

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@ducin
Comment options

@TkDodo
Comment options

@ducin
Comment options

@TkDodo
Comment options

@ducin
Comment options

Answer selected by ducin
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