-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Describe the bug
In https://github.com/TanStack/query/blob/main/packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.ts#L83 an identifier is only de-referenced if the target is an array.
This was written when the rule wasn't able to handle key factories (see TODO near the original commit: 82adc95#diff-1db59b20778c62ed3511c0664212006c2217e7c1ca7d07b79062b6e93fa3fc8b )
I wold think identifiers can always be de-referenced?
Anyway, this causes code like this
function queryKeyFactory(dependency: string) {
return ["my-key", dependency];
}
function example(dependency: string) {
const queryKey = queryKeyFactory(dependency);
return queryOptions({
queryKey,
queryFn: () => Promise.resolve(dependency),
})
}
to fail with "error The following dependencies are missing in your queryKey: dependency"
Note that there's a similar issue for as-expression in the same file in line 72.
Your minimal, reproducible example
Steps to reproduce
- Open ESLint Playground
- Observe error message in problems tab
- (optional) inline either
queryKey
variable orqueryKeyFactory
function to see error disappear
Expected behavior
As a developer I would like to be able to combine variables with functions for query keys without ESLint errors.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: Linux
- Node: v22.19.0
Tanstack Query adapter
vanilla
TanStack Query version
5.83.1
TypeScript version
No response
Additional context
No response