Skip to content
Source
Sign inSign up
TanStack/query

Wrong inferring in useInfiniteQuery #7301

Send to my agent
ClosedArianHamdi(GitHub profile, opens in a new tab) opened this issue 3 comments

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

  1. TkDodo closed this

  2. TkDodo added labelsduplicate

  3. order matters:

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

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

Sign in to join this conversation.