@@ -5,25 +5,25 @@ import type { DataTag, InfiniteData } from '@tanstack/query-core'
55
66describe ( 'getQueryData' , ( ) => {
77 it ( 'should be typed if key is tagged' , ( ) => {
8- const queryKey = [ 'key' ] as DataTag < Array < string > , number >
8+ const key = [ 'key' ] as DataTag < Array < string > , number >
99 const queryClient = new QueryClient ( )
10- const data = queryClient . getQueryData ( queryKey )
10+ const data = queryClient . getQueryData ( key )
1111
1212 expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
1313 } )
1414
1515 it ( 'should infer unknown if key is not tagged' , ( ) => {
16- const queryKey = [ 'key' ] as const
16+ const key = [ 'key' ] as const
1717 const queryClient = new QueryClient ( )
18- const data = queryClient . getQueryData ( queryKey )
18+ const data = queryClient . getQueryData ( key )
1919
2020 expectTypeOf ( data ) . toEqualTypeOf < unknown > ( )
2121 } )
2222
2323 it ( 'should infer passed generic if passed' , ( ) => {
24- const queryKey = [ 'key' ] as const
24+ const key = [ 'key' ] as const
2525 const queryClient = new QueryClient ( )
26- const data = queryClient . getQueryData < number > ( queryKey )
26+ const data = queryClient . getQueryData < number > ( key )
2727
2828 expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
2929 } )
@@ -38,74 +38,74 @@ describe('getQueryData', () => {
3838
3939describe ( 'setQueryData' , ( ) => {
4040 it ( 'updater should be typed if key is tagged' , ( ) => {
41- const queryKey = [ 'key' ] as DataTag < Array < string > , number >
41+ const key = [ 'key' ] as DataTag < Array < string > , number >
4242 const queryClient = new QueryClient ( )
43- const data = queryClient . setQueryData ( queryKey , ( prev ) => {
43+ const data = queryClient . setQueryData ( key , ( prev ) => {
4444 expectTypeOf ( prev ) . toEqualTypeOf < number | undefined > ( )
4545 return prev
4646 } )
4747 expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
4848 } )
4949
5050 it ( 'value should be typed if key is tagged' , ( ) => {
51- const queryKey = [ 'key' ] as DataTag < Array < string > , number >
51+ const key = [ 'key' ] as DataTag < Array < string > , number >
5252 const queryClient = new QueryClient ( )
5353
5454 // @ts -expect-error value should be a number
55- queryClient . setQueryData ( queryKey , '1' )
55+ queryClient . setQueryData ( key , '1' )
5656
5757 // @ts -expect-error value should be a number
58- queryClient . setQueryData ( queryKey , ( ) => '1' )
58+ queryClient . setQueryData ( key , ( ) => '1' )
5959
60- const data = queryClient . setQueryData ( queryKey , 1 )
60+ const data = queryClient . setQueryData ( key , 1 )
6161
6262 expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
6363 } )
6464
6565 it ( 'should infer unknown for updater if key is not tagged' , ( ) => {
66- const queryKey = [ 'key' ] as const
66+ const key = [ 'key' ] as const
6767 const queryClient = new QueryClient ( )
68- const data = queryClient . setQueryData ( queryKey , ( prev ) => {
68+ const data = queryClient . setQueryData ( key , ( prev ) => {
6969 expectTypeOf ( prev ) . toEqualTypeOf < unknown > ( )
7070 return prev
7171 } )
7272 expectTypeOf ( data ) . toEqualTypeOf < unknown > ( )
7373 } )
7474
7575 it ( 'should infer unknown for value if key is not tagged' , ( ) => {
76- const queryKey = [ 'key' ] as const
76+ const key = [ 'key' ] as const
7777 const queryClient = new QueryClient ( )
78- const data = queryClient . setQueryData ( queryKey , 'foo' )
78+ const data = queryClient . setQueryData ( key , 'foo' )
7979
8080 expectTypeOf ( data ) . toEqualTypeOf < unknown > ( )
8181 } )
8282
8383 it ( 'should infer passed generic if passed' , ( ) => {
84- const queryKey = [ 'key' ] as const
84+ const key = [ 'key' ] as const
8585 const queryClient = new QueryClient ( )
86- const data = queryClient . setQueryData < string > ( queryKey , ( prev ) => {
86+ const data = queryClient . setQueryData < string > ( key , ( prev ) => {
8787 expectTypeOf ( prev ) . toEqualTypeOf < string | undefined > ( )
8888 return prev
8989 } )
9090 expectTypeOf ( data ) . toEqualTypeOf < string | undefined > ( )
9191 } )
9292
9393 it ( 'should infer passed generic for value' , ( ) => {
94- const queryKey = [ 'key' ] as const
94+ const key = [ 'key' ] as const
9595 const queryClient = new QueryClient ( )
96- const data = queryClient . setQueryData < string > ( queryKey , 'foo' )
96+ const data = queryClient . setQueryData < string > ( key , 'foo' )
9797
9898 expectTypeOf ( data ) . toEqualTypeOf < string | undefined > ( )
9999 } )
100100
101101 it ( 'should preserve updater parameter type inference when used in functions with explicit return types' , ( ) => {
102- const queryKey = [ 'key' ] as DataTag < Array < string > , number >
102+ const key = [ 'key' ] as DataTag < Array < string > , number >
103103 const queryClient = new QueryClient ( )
104104
105105 // Simulate usage inside a function with explicit return type
106106 // The outer function returns 'unknown' but this shouldn't affect the updater's type inference
107107 ; ( ( ) =>
108- queryClient . setQueryData ( queryKey , ( data ) => {
108+ queryClient . setQueryData ( key , ( data ) => {
109109 expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
110110 return data
111111 } ) ) satisfies ( ) => unknown
0 commit comments