-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript incorrectly narrows error
based on isLoading
#7105
Comments
can you show this in a runtime sandbox, because if query/packages/query-core/src/query.ts Lines 561 to 564 in 549862e
if a fetch comes in and we have no data, |
Alright, I created a sandbox mwe. To see it:
and then it'll be almost instantly followed by a re-render where Btw, for context: why is this an issue? Because I'm resorting to |
Describe the bug
If I do
error
is assumed to benull
by typescript. That's wrong: if it's the first time the query is used, then yes, that's right. But if:isLoading === false
anderror !== null
isLoading === true
again), buterror
will be initialized with the previouserror
, so we haveerror !== null
while alsoisLoading === true
.So either the types or the implementation are wrong. I'm hoping for the types being wrong, because I like this behavior 😅
In case it helps: the same implementation behavior is present with
isFetching
(so, you can haveisFetching === true
while also havingerror !== null
), but the type narrowing doesn't kick in that case.Your minimal, reproducible example
Ts Playground
Steps to reproduce
Since I'm hoping for this to be a bug in the types and not the implementation, I'm providing a Ts Playground as MWE. But if you folks tell me this is an implementation bug, I can create a codesandbox instead.
Expected behavior
Type narrowing match implementation
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
None
TanStack Query version
5.25.0
TypeScript version
5.3.3
Additional context
No response
The text was updated successfully, but these errors were encountered: