Describe the bug
Up to v2.7.1, the return type of prefetchQuery was Promise<TResult>. In v2.8.0, however, the return type was changed for Promise<TResult | undefined>. I'm guessing this is wrong.. Or is there a situation where prefetchQuery can return Promise<undefined>?
Hi @lgenzelis ! By default the prefetchQuery method will return Promise<undefined> when the query fails. This is something which can definitely happen during runtime.
Thanks @boschni ! Are you sure? I mean, I'd expect the Promise to be rejected if the query failed, not to resolve with undefined. That was the behavior up to 2.7.1, at least. It seems counterintuitive (to me, at least) .
Yeah that would also be my first assumption (especially with the previous types). But it will only throw if the throwOnError option is explicitly set to true (see https://github.com/tannerlinsley/react-query/blob/master/src/core/queryCache.ts#L314) and this behaviour has not changed to my knowledge.
@tannerlinsley would it be an idea to remove this option as the caller can always choose to handle the promise rejection or not? Or we could always return a QueryResult?
It would be a breaking change, so let's discuss it more in v3. I'll add it to the umbrella issue.
Most helpful comment
Yeah that would also be my first assumption (especially with the previous types). But it will only throw if the
throwOnErroroption is explicitly set totrue(see https://github.com/tannerlinsley/react-query/blob/master/src/core/queryCache.ts#L314) and this behaviour has not changed to my knowledge.@tannerlinsley would it be an idea to remove this option as the caller can always choose to handle the promise rejection or not? Or we could always return a
QueryResult?