Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sazzer opened this issue May 6, 2024 · 2 comments · Fixed by #7419

Comments

@sazzer
Copy link
Contributor

sazzer commented May 6, 2024

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

@TkDodo
Copy link
Collaborator

TkDodo commented May 10, 2024

@Newbie012 can you take a look please ?

@Newbie012
Copy link
Collaborator

Should be fixed once #7419 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants