Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exhaustive-deps incorrectly treats external value as dependency #8008

Open
selrond opened this issue Sep 3, 2024 · 1 comment
Open

exhaustive-deps incorrectly treats external value as dependency #8008

selrond opened this issue Sep 3, 2024 · 1 comment
Labels

Comments

@selrond
Copy link

selrond commented Sep 3, 2024

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

@TkDodo TkDodo added bug Something isn't working package: eslint-plugin-query labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants