Skip to content

eslint: exhaustive-deps false positive for optional chain #8357

@Jack-Works

Description

@Jack-Works

Describe the bug

declare function sendQuery(address: string): Promise<any>
function useTest(data?: any) {
    return useQuery({
        // The following dependencies are missing in your queryKey: data
        queryKey: ['query-name', data?.address],
        queryFn: async () => sendQuery(data!.address),
        enabled: !!data?.address,
    })
}
declare function sendQuery(address: string): Promise<any>
function useTest(data?: any) {
    return useQuery({
        // The following dependencies are missing in your queryKey: data.address
        queryKey: ['query-name', data?.address],
        queryFn: async () => sendQuery(data.address),
        enabled: !!data?.address,
    })
}

Your minimal, reproducible example

...

Steps to reproduce

  1. enable rule @tanstack/query/exhaustive-deps

Expected behavior

No error

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • "@tanstack/eslint-plugin-query": "^5.61.4"

Tanstack Query adapter

None

TanStack Query version

not applicable

TypeScript version

5.7.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions