Skip to content

false-positives in eslint-plugin-query (exhaustive-deps) #5022

@TkDodo

Description

@TkDodo

After upgrading from 4.15.1 to 4.24.8, I have seen two false-positives for the exhaustive-deps rule in our product. I've narrowed it down and created failing test cases

  1. new Error('') in the queryFn errors with:
'The following dependencies are missing in your queryKey: Error'

failing test-case to reproduce:

{
  name: 'should not treat new Error as missing dependency',
  code: normalizeIndent`
    useQuery({
      queryKey: ['foo'],
      queryFn: () => Promise.reject(new Error('1')),
    })
  `,
},
  1. it fails to work if there is an inline const assertion:

failing test-case to reproduce

{
  name: 'should see id when there is a const assertion',
  code: normalizeIndent`
    const useX = (id: number) => {
      return useQuery({
        queryKey: ['foo', id] as const,
        queryFn: async () => id,
      })
    }
  `,
},

it errors with:

'The following dependencies are missing in your queryKey: id'`

note that it works fine if you remove as const.

@Newbie012 fyi

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions