Skip to content
Source
Sign inSign up
TanStack/query

exhaustive-deps incorrectly treats external value as dependency #8008

Send to my agent
Closedselrond(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

exhaustive-deps incorrectly treats zod schema as a dependency

Steps to reproduce

I have this code, which I use in useQuery calls:

import { z } from 'zod'

interface ValidateRequestParams<TSchema> {
  schema: TSchema
  request: (...params: Array<unknown>) => Promise<unknown>
}

export async function validatedRequest<TSchema extends z.ZodTypeAny>({
  schema,
  request,
}: ValidateRequestParams<TSchema>) {
  const response = await request()
  return schema.parse(response) as z.infer<TSchema>
}

const FeatureFlagsSchema = z.string().array()

export const queries = {
  root: () => ['featureFlags'],
  getAll: () =>
    queryOptions({
      queryKey: queries.root(),
//    ^^^^^^^^^^^^^^^^^^^^^^^^ The following dependencies are missing in your queryKey: FeatureFlagsSchema
      queryFn: () =>
        validatedRequest({
          schema: FeatureFlagsSchema,
          request: () => Api.get(`/api/v1/features`),
        }),
    }),
}

There have been multiple similar reports, some fixed, but it seems it’s still an issue.

Dependencies:

"@tanstack/eslint-plugin-query": "^5.53.0",
"@tanstack/react-query": "^5.53.2",

Expected behavior

I expect it to not report external values as dependencies

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

irrelevant I believe

Tanstack Query adapter

react-query

TanStack Query version

v5.53.2

TypeScript version

5.5.4

Additional context

No response

Sign in to join this conversation.