@@ -549,6 +549,13 @@ describe('InfiniteQuery', () => {
549549 initialPageParam : { offset : 0 , limit : 10 } ,
550550 // eslint-disable-next-line @typescript-eslint/no-unused-vars
551551 getNextPageParam : ( page , allPages , lastPageParam ) => {
552+ expectTypeOf ( page ) . toEqualTypeOf < Foo [ ] > ( ) ;
553+ expectTypeOf ( allPages ) . toEqualTypeOf < Foo [ ] [ ] > ( ) ;
554+ expectTypeOf ( lastPageParam ) . toEqualTypeOf < {
555+ offset : number ;
556+ limit : number ;
557+ } > ( ) ;
558+
552559 if ( globalThis ) {
553560 return null ;
554561 }
@@ -573,6 +580,45 @@ describe('InfiniteQuery', () => {
573580 > ( ) ;
574581 } ) ;
575582
583+ it ( 'getNextPageParam typings with dynamic options' , ( ) => {
584+ type Foo = { foo : 1 } ;
585+
586+ const getFoo = ( ) : Foo [ ] => [ ] ;
587+
588+ const infiniteQuery = new InfiniteQuery ( new QueryClient ( { } ) , ( ) => ( {
589+ queryKey : [ 'allCharacters' , [ '1' , '2' ] ] ,
590+ initialPageParam : 1 ,
591+ queryFn : async ( ) => {
592+ return getFoo ( ) ;
593+ } ,
594+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
595+ getNextPageParam : ( page , allPages , lastPageParam ) => {
596+ expectTypeOf ( page ) . toEqualTypeOf < Foo [ ] > ( ) ;
597+ expectTypeOf ( allPages ) . toEqualTypeOf < Foo [ ] [ ] > ( ) ;
598+ expectTypeOf ( lastPageParam ) . toEqualTypeOf < number > ( ) ;
599+
600+ if ( globalThis ) {
601+ return null ;
602+ }
603+ return 2 ;
604+ } ,
605+ } ) ) ;
606+
607+ expectTypeOf ( infiniteQuery . result . data ) . toEqualTypeOf <
608+ | undefined
609+ | {
610+ pageParams : number [ ] ;
611+ pages : Foo [ ] [ ] ;
612+ }
613+ > ( ) ;
614+
615+ const anotherTest =
616+ ( infiniteQuery . data ?. pages . flat ( ) . length ?? 0 ) -
617+ ( infiniteQuery . data ?. pages . at ( - 1 ) ?. length ?? 0 ) ;
618+
619+ expectTypeOf ( anotherTest ) . toEqualTypeOf < number > ( ) ;
620+ } ) ;
621+
576622 it ( 'update() method parameters (throwOnError)' , ( ) => {
577623 type Foo = { foo : 1 } ;
578624
0 commit comments