You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inference is broken for object generics with return function #46977
functionuseQuery<TQueryKey,TData>(_options: {queryKey: TQueryKey;queryFn: (context?: {queryKey: TQueryKey})=>TData;onSuccess: (data: TData)=>void;}){}constqueryKey=["test",1,2,{3: true}]// no context no cryuseQuery({
queryKey,queryFn: (): number=>1,onSuccess: (data)=>data.toFixed(),});// as soon as I use ctx, data is no longer of type number for onSuccessuseQuery({
queryKey,queryFn: (ctx): number=>1,// Why is `data` of type `any`?onSuccess: (data)=>data.toFixed(),});
🙁 Actual behavior
In the second example the data argument on the onSuccess function is typed as any.
🙂 Expected behavior
In the second example the data argument should be typed as the return value of the queryFn property, or more specifically, number
Activity
tannerlinsley commentedon Dec 1, 2021
cc Dominik Dorfmeister 🔮 (@TkDodo)
MartinJohns commentedon Dec 1, 2021
Pretty sure it's the same as #43371.
tannerlinsley commentedon Dec 1, 2021
Thanks Martin Johns (@MartinJohns). I'll track it there.