Skip to content

eslint exhaustive-deps incorrectly labelling constant value as key dependency #8326

@MarkSFrancis

Description

@MarkSFrancis

Describe the bug

@tanstack/eslint-plugin-query@5.60.1

incorrect exhaustive-deps error for constant values when using them in queryOptions + in a const scope

import { queryOptions } from '@tanstack/react-query';

const EXAMPLE_CONST = 1;

// This works great
export const thisDoesNotShowError = () => ({
  q3: queryOptions({
    queryKey: ['getAll'],
    queryFn: () => Promise.resolve(EXAMPLE_CONST),
  }),
});

// This shows an "The following dependencies are missing in your queryKey: EXAMPLE_CONST" error
export const thisShowsError = {
  q3: queryOptions({
    queryKey: ['getAll'],
    queryFn: () => Promise.resolve(EXAMPLE_CONST),
  }),
};
npx eslint ./test.ts

/workspace/example.ts
  16:5  error  The following dependencies are missing in your queryKey: EXAMPLE_CONST  @tanstack/query/exhaustive-deps

✖ 1 problem (1 error, 0 warnings)

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-jx3ix8?file=src%2Ftest.ts

Steps to reproduce

  1. Create an object with properties
  2. Use queryOptions in one of those property definitions
  3. Access a const outside the scope of the function
  4. ESLint will flag the @tanstack/query/exhaustive-deps rule violation

Expected behavior

Constants should not count as a dependency

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

VSCode

Tanstack Query adapter

None

TanStack Query version

v5.59.9

TypeScript version

v5.3.3

Additional context

Likely related to #5196, which was fixed in #5446

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions