TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
42.56k stars 2.91k forks source link

ESLint rule `@tanstack/query/exhaustive-deps` reports missing dependencies when using optional changing #8112

Closed nickrttn closed 1 month ago

nickrttn commented 1 month ago

Describe the bug

The ESLint rule @tanstack/query/exhaustive-deps reports false positive missing dependencies when using optional chaining in the queryKey.

Your minimal, reproducible example

https://stackblitz.com/edit/stackblitz-starters-rqku3u?file=app%2Fuse-users.ts

Steps to reproduce

  1. Go to https://stackblitz.com/edit/stackblitz-starters-rqku3u?file=app%2Fuse-users.ts
  2. Run npx eslint . in the terminal

Expected behavior

I would not expect an error to be shown when linting. I would expect the optional chaining to be valid.

How often does this bug happen?

Every time

Screenshots or Videos

Image

Platform

Tanstack Query adapter

react-query

TanStack Query version

5.45.1

TypeScript version

5.6.2

Additional context

No response

TkDodo commented 1 month ago

do you want to work on this @nickrttn ?

nickrttn commented 1 month ago

Sure! I can take a look

TkDodo commented 1 month ago

This got fixed with: