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

fix(react-query): fix no type error on wrong type annotation in useQuery #8683

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

skiende74
Copy link

closes #7530

 const queryResult: UseQueryResult<number> = useQuery({
    queryKey: ['key'],
    queryFn: async () => 'not a number',
  });

This should produce a type error because the correct type for queryResult should be UseQueryResult<string>.
Previously, due to reverse type inference from the return type context, no error was detected when using the wrong type annotation.

This PR prevents reverse type inference from the result type annotation, ensuring that incorrect type annotations are caught as type errors.

@skiende74 skiende74 changed the title fix(react-query): Prevent reverse type inference causing no error on wrong type annotation in useQuery fix(react-query): fix no error on wrong type annotation in useQuery Feb 21, 2025
@skiende74 skiende74 changed the title fix(react-query): fix no error on wrong type annotation in useQuery fix(react-query): fix no type error on wrong type annotation in useQuery Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useQuery() hook vulnerable to type errors
1 participant