TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
40.1k stars 2.69k forks source link

Wrong inferring in useInfiniteQuery #7301

Closed ArianHamdi closed 4 weeks ago

ArianHamdi commented 4 weeks ago

Describe the bug

In useInfiniteQuery, thequeryFn randomly infers unknown instead of the actual data type.

Your minimal, reproducible example

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgVwM4FMCSA7AZsbYGdARWXSgE84BfOXKCEOAcgAEYBDbVLgYwDWAeijpOfGAFoAjuSosA3AFgAUKtXoAHpFhw+EHvDToAwmhhMAEhAgCAjHAC8cABQBKJwD5EquHFEwyFDYKBg4+ITEZBSULgi+fnCyMQDS6JQAXHAA2ix85kwsALoANAl+BETAnAA2AAqcAOboDVCcIFkADGUqiXDNMAByWjANza3tWS41nLxj6B6O3t3lcEJCBLgUKNgC2BAA7tiryVQAYthTSDSL3vG9ff7ogcE5diVwAEwfAMxFqzQen4bsoVDRQRptNB4PpDKFTAUQNZbJ8nK5bj4HgEgiFjOFKlE5LF7n1TpQ0pkcnlEcUgYkCdV6k0Wpw2h04CsHn4BsNNKNmRN2dNZvzmhjOX11qIQBAAG7oOAAE3QvCgyAkQXQq3Wm222GQIAARhRsv8uUkiRcphiSY9sa9su8vr8zX1AQkQapweoVFodDCDLx4WZeFYbAIfmj3F5MX57biwngCaQiXFtUIZfKLTELnALHmABYKixgdO6qBwfVGk2uxJkq2ua421Zx544t4fb5wP4Aul+MkUrK5fKhkC01YM2rzQVdPv9Z680UstlTGZzZnij1uUHgoA

Steps to reproduce

Hover over queryFn in useCustomHook1. The inferred type is unknown, but it is inferred correctly in useCustomHook2 and useCustomHook3.

Expected behavior

It should always infer correctly.

How often does this bug happen?

Sometimes

Screenshots or Videos

image

Platform

Doesn't matter

Tanstack Query adapter

react-query

TanStack Query version

5.29.2

TypeScript version

5.4.5

Additional context

No response

TkDodo commented 4 weeks ago

order matters:

ArianHamdi commented 4 weeks ago

order matters:

Actually destructuring in queryFn is breaking inferring which I don't understand why this is happening.

image
TkDodo commented 4 weeks ago

also part of the typescript limitation. it's outlined in the reproduction in the linked issue.