Skip to content

[lint]: no-rest-destructuring does not report on custom hooks #8951

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

Open
zbarbuto opened this issue Apr 4, 2025 · 5 comments
Open

[lint]: no-rest-destructuring does not report on custom hooks #8951

zbarbuto opened this issue Apr 4, 2025 · 5 comments
Labels

Comments

@zbarbuto
Copy link

zbarbuto commented Apr 4, 2025

Describe the bug

When using custom hooks for a query function, the no-rest-destructuring does not report.

Steps to reproduce

// Custom hook for query
const useTodos = () => {
  return useQuery({
    queryKey: ['todos'],
    queryFn: () => fetch('example.com/todos'),
  });
  // NB results the same with const result = useQuery(/* */); return result;
};

function TodoList() {
  // ✅ Normal usage - issue reported
  const { dataA, ...restA } = useQuery({
    queryKey: ['todos'],
    queryFn: () => fetch('example.com/todos'),
  });

  // ❌ Custom hook - no issue reported
  const { dataB, ...restB } = useTodos();

  return <></>;
}

Expected behavior

Should report destructuring error when using const { ...rest } = useCustomQueryHook()

TanStack Query version

React query v5.50.1, eslint-plugin-query v5.71.5

TypeScript version

5.8.2

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 4, 2025

yeah I’ve seen that too, not sure if it’s doable, especially if the hook is imported from a different file. @Newbie012 what do you think?

@Newbie012
Copy link
Collaborator

It is if I check the hook's return type, but it will require type checking and will work only for projects using typescript-eslint.

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 4, 2025

if we want this, I think we’d need a separate config recomended-typechecking ?

@zbarbuto
Copy link
Author

zbarbuto commented Apr 6, 2025

Importing from a different file is pretty much my main use-case.
TypeScript-only would be fine IMO, even if it was separate config.

@Newbie012
Copy link
Collaborator

if we want this, I think we’d need a separate config recomended-typechecking ?

Somewhat related to #8966. I can add a flag for the rule to explicitly fallback to using ts.TypeChecker when using .recommendedTypeChecked

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

No branches or pull requests

3 participants