@@ -50,6 +50,20 @@ describe('infiniteQueryOptions', () => {
5050 InfiniteData < string , unknown > | undefined
5151 > ( )
5252 } )
53+ it ( 'should work when passed to useInfiniteQuery with select' , ( ) => {
54+ const options = infiniteQueryOptions ( {
55+ queryKey : [ 'key' ] ,
56+ queryFn : ( ) => Promise . resolve ( 'string' ) ,
57+ getNextPageParam : ( ) => 1 ,
58+ initialPageParam : 1 ,
59+ select : ( data ) => data . pages ,
60+ } )
61+
62+ const { data } = useInfiniteQuery ( options )
63+
64+ // known issue: type of pageParams is unknown when returned from useInfiniteQuery
65+ expectTypeOf ( data ) . toEqualTypeOf < Array < string > | undefined > ( )
66+ } )
5367 it ( 'should work when passed to useSuspenseInfiniteQuery' , ( ) => {
5468 const options = infiniteQueryOptions ( {
5569 queryKey : [ 'key' ] ,
@@ -62,6 +76,47 @@ describe('infiniteQueryOptions', () => {
6276
6377 expectTypeOf ( data ) . toEqualTypeOf < InfiniteData < string , unknown > > ( )
6478 } )
79+ it ( 'should work when passed to useSuspenseInfiniteQuery with select' , ( ) => {
80+ const options = infiniteQueryOptions ( {
81+ queryKey : [ 'key' ] ,
82+ queryFn : ( ) => Promise . resolve ( 'string' ) ,
83+ getNextPageParam : ( ) => 1 ,
84+ initialPageParam : 1 ,
85+ select : ( data ) => data . pages ,
86+ } )
87+
88+ const { data } = useSuspenseInfiniteQuery ( options )
89+
90+ // known issue: type of pageParams is unknown when returned from useInfiniteQuery
91+ expectTypeOf ( data ) . toEqualTypeOf < Array < string > > ( )
92+ } )
93+ it ( 'should work when passed to infiniteQuery' , async ( ) => {
94+ const options = infiniteQueryOptions ( {
95+ queryKey : [ 'key' ] ,
96+ queryFn : ( ) => Promise . resolve ( 'string' ) ,
97+ getNextPageParam : ( ) => 1 ,
98+ initialPageParam : 1 ,
99+ } )
100+
101+ const data = await new QueryClient ( ) . infiniteQuery ( options )
102+
103+ expectTypeOf ( data ) . toEqualTypeOf < InfiniteData < string , number > > ( )
104+ } )
105+ it ( 'should work when passed to infiniteQuery with select' , async ( ) => {
106+ const options = infiniteQueryOptions ( {
107+ queryKey : [ 'key' ] ,
108+ queryFn : ( ) => Promise . resolve ( 'string' ) ,
109+ getNextPageParam : ( ) => 1 ,
110+ initialPageParam : 1 ,
111+ select : ( data ) => data . pages ,
112+ } )
113+
114+ options . select
115+
116+ const data = await new QueryClient ( ) . infiniteQuery ( options )
117+
118+ expectTypeOf ( data ) . toEqualTypeOf < InfiniteData < string , number > > ( )
119+ } )
65120 it ( 'should work when passed to fetchInfiniteQuery' , async ( ) => {
66121 const options = infiniteQueryOptions ( {
67122 queryKey : [ 'key' ] ,
@@ -74,6 +129,19 @@ describe('infiniteQueryOptions', () => {
74129
75130 expectTypeOf ( data ) . toEqualTypeOf < InfiniteData < string , number > > ( )
76131 } )
132+ it ( 'should ignore select when passed to fetchInfiniteQuery' , async ( ) => {
133+ const options = infiniteQueryOptions ( {
134+ queryKey : [ 'key' ] ,
135+ queryFn : ( ) => Promise . resolve ( 'string' ) ,
136+ getNextPageParam : ( ) => 1 ,
137+ initialPageParam : 1 ,
138+ select : ( data ) => data . pages ,
139+ } )
140+
141+ const data = await new QueryClient ( ) . fetchInfiniteQuery ( options )
142+
143+ expectTypeOf ( data ) . toEqualTypeOf < InfiniteData < string , number > > ( )
144+ } )
77145 it ( 'should tag the queryKey with the result type of the QueryFn' , ( ) => {
78146 const { queryKey } = infiniteQueryOptions ( {
79147 queryKey : [ 'key' ] ,
0 commit comments