@@ -113,6 +113,19 @@ describe('setQueryData', () => {
113
113
114
114
expectTypeOf ( data ) . toEqualTypeOf < string | undefined > ( )
115
115
} )
116
+
117
+ it ( 'should preserve updater parameter type inference when used in functions with explicit return types' , ( ) => {
118
+ const queryKey = [ 'key' ] as DataTag < Array < string > , number >
119
+ const queryClient = new QueryClient ( )
120
+
121
+ // Simulate usage inside a function with explicit return type
122
+ // The outer function returns 'unknown' but this shouldn't affect the updater's type inference
123
+ ; ( ( ) =>
124
+ queryClient . setQueryData ( queryKey , ( data ) => {
125
+ expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
126
+ return data
127
+ } ) ) satisfies ( ) => unknown
128
+ } )
116
129
} )
117
130
118
131
describe ( 'getQueryState' , ( ) => {
@@ -590,3 +603,28 @@ describe('resetQueries', () => {
590
603
} )
591
604
} )
592
605
} )
606
+ type SuccessCallback = ( ) => unknown
607
+ it ( 'should infer types correctly with expression body arrow functions' , ( ) => {
608
+ const queryKey = [ 'key' ] as DataTag < Array < string > , number >
609
+ const queryClient = new QueryClient ( )
610
+
611
+ // @ts -expect-error
612
+ const callbackTest : SuccessCallback = ( ) =>
613
+ queryClient . setQueryData ( queryKey , ( data ) => {
614
+ expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
615
+ return data
616
+ } )
617
+ } )
618
+
619
+ it ( 'should infer types correctly with block body arrow functions' , ( ) => {
620
+ const queryKey = [ 'key' ] as DataTag < Array < string > , number >
621
+ const queryClient = new QueryClient ( )
622
+
623
+ // @ts -expect-error
624
+ const callbackTest2 : SuccessCallback = ( ) => {
625
+ queryClient . setQueryData ( queryKey , ( data ) => {
626
+ expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
627
+ return data
628
+ } )
629
+ }
630
+ } )
0 commit comments