query icon indicating copy to clipboard operation
query copied to clipboard

exhaustive-deps incorrectly treats external value as dependency

Open selrond opened this issue 1 year ago β€’ 1 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

selrond avatar Sep 03 '24 09:09 selrond

Confirmed, this shouldn't be the case. @Newbie012 can you have a look please? Error reproduced here:

https://eslint-online-playground.netlify.app/#eNp9U01v2zAM/SuELnGAVsauATqswJDLDsM+bnWHCjbtqpMlTZLTOoH/+yjJLhw0rU60+Pj4+CifmHd1iS+itwr5k2c7JntrXIATHGGC1pkeNkfTbCpdaXxJKeFHXUM76DpIo+EglGxEwOYn/hvQh+JUaQBfP2IvrmLo8j3F0xZSsjbaB7r3lgKEGxDPQsaLTLDNVWFweubhVjiPxVJBgCkKyjx7FATFvRKd/5XgxHjkPjipu2LLhXNijKSvE+Q6auYkegInUc6YsINiCzef4W7Trkg392mODsOtUjMkXkCiGL/b6IPPc7/efsNxt7TgkbvYEktZRsCfdw78fkRojVLmmaRDgxZ1g7qOKoVD6KX3MSE1jGZwq0ZvPTgTs9dnsuO5vLblZNsv8SYrljNvbLHt1kpOLhUPpbCyPHwqZxf9Q5x9KZqWjxRM7IqhV1IHTmtpZXf2DK0aOql/xBnmx/glCFqeqP+Wueo6Q67TnOtn2mArBhXgLjbjnK+o5k6e1qxEKB3Wpu+j1U1a9X2lSZSlHqKLf4XRJCjZU7EwWqzYjqLeNIOiOA1TsQYPX1f7ipjZ0Yp9qDmzkQ4ycmZLNRlaPiWqC4CcP0/GHP0ZE5v+A/YOTm8=

TkDodo avatar Sep 08 '24 16:09 TkDodo

I'm not sure how I missed this issue... in any case, is it still relevant? I don't see the error being reported in the reproduced link

Newbie012 avatar Jan 08 '25 12:01 Newbie012

yeah might be that we implicitly fixed it πŸŽ‰

TkDodo avatar Jan 08 '25 13:01 TkDodo