query icon indicating copy to clipboard operation
query copied to clipboard

JSDoc return type inference broken for useQuery/createQuery, but not for useMutation/createMutation

Open PhilippMolitor opened this issue 1 year ago • 1 comments

Describe the bug

When typing createQuery and createMutation with jsdoc comments, the return data type gets inferred correctly for the mutationFn, but not for queryFn. If i mistype the data in a query, i will not get a warning. For mutations, that works.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-query-jsdoc?file=src%2Flib%2Ftest.js

Steps to reproduce

Have a look at the stackblitz demo, in the comments it is described how to see that type inference behaves inconsistently.

Expected behavior

queryFn should infer from the attached jsdoc type at createQuery just like createMutation does. Other types of create... could be affected as well.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • macOS latest
  • VSCode 1.91
  • Node 20.15.0

Tanstack Query adapter

svelte-query

TanStack Query version

5.49.0

TypeScript version

Additional context

No response

PhilippMolitor avatar Jul 04 '24 06:07 PhilippMolitor

Hi @PhilippMolitor , I've tried this with @tanstack/react-query and it has the same limitation. Both share the underlying QueryObserverResult and MutationObserverResult types.

lachlancollins avatar Jul 18 '24 01:07 lachlancollins