False positive in @tanstack/query/exhaustive-deps when combining query key variable with function invocation #9643
Send to my agentDescribe 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: https://github.com/TanStack/query/commit/82adc95c2403a2f63aa9554223f0140f02497111#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
queryKeyvariable orqueryKeyFactoryfunction 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
TkDodo added labelspackage: eslint-plugin-query
I submitted a PR.
I wasn't sure if variable and type assertion de-referencing ought to be integrated into
ASTUtils.getNestedIdentifiers, so I left it separate.TkDodo closed this
I'm still getting this error with my code, not sure if I should open a new issue or we reopen this one?
/Users/blake/Projects/Exceptionless/Exceptionless/src/Exceptionless.Web/ClientApp/src/lib/features/users/api.svelte.ts 108:9 error The following dependencies are missing in your queryKey: request.params.limit @tanstack/query/exhaustive-deps
queryKey: [...queryKeys.organization(request.route.organizationId), { params: request.params }]
Sign in to join this conversation.
would you like to contribute this improvement ?