-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
Describe the bug
Context
I'm trying to do query invalidation based using predicates. For the particular use case, I would like to know if the query is enabled, since the typing of the queryKey may vary with it.
By using console log, I know that the queries in the query cache can have the query.options.enabled
property, which I would like to use. Using query.isDisabled()
is not equivalent, since it can return false even queries with enabled: false
.
Issue
const queryClient = useQueryClient()
queryClient.invalidateQueries({
predicate: (query) => {
// query.options.enabled is not included in typing, but it is part of the object if we console log.
return false
},
})
Your minimal, reproducible example
https://stackblitz.com/edit/react-ts-dc5yox?file=App.tsx
Steps to reproduce
- Create a query, and call it using
{enabled: false}
- Call the query client, and try doing query invalidation using
predicate:
console.log
the queries, you will see that the one that hasenabled: false
will appear as having it on:
{
...
options: {
...
enabled: false
}
}
- Even though this happens, the typescript type says the
{enabled? : boolean}
property is not on the options object.
Expected behavior
I expected to have
query.options: typeof query.options & {enabled? : boolean}
as the type of the query options
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- Linux - Ubuntu
- Firefox and Chrome
TanStack Query version
4.20.4
TypeScript version
4.9.3
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels