query icon indicating copy to clipboard operation
query copied to clipboard

eslint-plugin-query: @tanstack/query/exhaustive-deps is triggered for a type used in an instanceof call.

Open sazzer opened this issue 1 year ago • 1 comments

Describe the bug

I've got a query that's using instanceof to ensure that my API client is returning the expected type. The ESLint plugin is flagging this type as an unused dependency, even though that makes no sense.

Your minimal, reproducible example

Included in "Steps to reproduce"

Steps to reproduce

Note that this is using jotai-tanstack-query and this is all in TypeScript, but I assume that's irrelevant.

This reproduces the problem directly:

class SomeBaseResponse {}
class SomeResponse extends SomeBaseResponse {}

function someCall(): SomeBaseResponse {
  return new SomeResponse();
}

export const someQuery = atomWithSuspenseQuery(() => ({
  queryKey: ["someQuery"],
  queryFn: () => {
    const result = someCall();

    if (result instanceof SomeResponse) {
      return result;
    }

    throw new Error("Failed to get something");
  }
}));

The ESLint plugin then gives the following error for the queryKey line:

error The following dependencies are missing in your queryKey: SomeResponse @tanstack/query/exhaustive-deps

Expected behavior

I'd expect the plugin to understand that the typename being used isn't a dependency and so not flag it.

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

  • OS: macOS 14.4.1
  • Browser: Irrelevent
  • IDE: VSCode
  • Plugin versions:
    • "@tanstack/eslint-plugin-query": "^5.28.11",
    • "eslint": "^8.57.0",

Tanstack Query adapter

react-query

TanStack Query version

5.32.0

TypeScript version

5.4.5

Additional context

No response

sazzer avatar May 06 '24 16:05 sazzer

@Newbie012 can you take a look please ?

TkDodo avatar May 10 '24 12:05 TkDodo

Should be fixed once https://github.com/TanStack/query/pull/7419 is merged

Newbie012 avatar May 12 '24 07:05 Newbie012