@@ -591,21 +591,38 @@ const preEnhancer =
591591 } as any ;
592592 } ;
593593
594+ export type InferComposedStoreExt < StoreEnhancers > = StoreEnhancers extends [
595+ infer HeadStoreEnhancer ,
596+ ...infer RestStoreEnhancers
597+ ]
598+ ? HeadStoreEnhancer extends StoreEnhancer < infer StoreExt >
599+ ? StoreExt & InferComposedStoreExt < RestStoreEnhancers >
600+ : never
601+ : unknown ;
602+
594603const extensionCompose =
595604 ( config : Config ) =>
596- ( ...funcs : StoreEnhancer [ ] ) : StoreEnhancer => {
605+ < StoreEnhancers extends readonly StoreEnhancer < unknown > [ ] > (
606+ ...funcs : StoreEnhancers
607+ ) : StoreEnhancer < InferComposedStoreExt < StoreEnhancers > > => {
608+ // @ts -ignore FIXME
597609 return ( ...args ) => {
598610 const instanceId = generateId ( config . instanceId ) ;
599611 return [ preEnhancer ( instanceId ) , ...funcs ] . reduceRight (
612+ // @ts -ignore FIXME
600613 ( composed , f ) => f ( composed ) ,
601614 __REDUX_DEVTOOLS_EXTENSION__ ( { ...config , instanceId } ) ( ...args )
602615 ) ;
603616 } ;
604617 } ;
605618
606619interface ReduxDevtoolsExtensionCompose {
607- ( config : Config ) : ( ...funcs : StoreEnhancer [ ] ) => StoreEnhancer ;
608- ( ...funcs : StoreEnhancer [ ] ) : StoreEnhancer ;
620+ ( config : Config ) : < StoreEnhancers extends readonly StoreEnhancer < unknown > [ ] > (
621+ ...funcs : StoreEnhancers
622+ ) => StoreEnhancer < InferComposedStoreExt < StoreEnhancers > > ;
623+ < StoreEnhancers extends readonly StoreEnhancer < unknown > [ ] > (
624+ ...funcs : StoreEnhancers
625+ ) : StoreEnhancer < InferComposedStoreExt < StoreEnhancers > > ;
609626}
610627
611628declare global {
@@ -616,18 +633,24 @@ declare global {
616633
617634function reduxDevtoolsExtensionCompose (
618635 config : Config
619- ) : ( ...funcs : StoreEnhancer [ ] ) => StoreEnhancer ;
636+ ) : < StoreEnhancers extends readonly StoreEnhancer < unknown > [ ] > (
637+ ...funcs : StoreEnhancers
638+ ) => StoreEnhancer < InferComposedStoreExt < StoreEnhancers > > ;
639+ function reduxDevtoolsExtensionCompose <
640+ StoreEnhancers extends readonly StoreEnhancer < unknown > [ ]
641+ > (
642+ ...funcs : StoreEnhancers
643+ ) : StoreEnhancer < InferComposedStoreExt < StoreEnhancers > > ;
620644function reduxDevtoolsExtensionCompose (
621- ...funcs : StoreEnhancer [ ]
622- ) : StoreEnhancer ;
623- function reduxDevtoolsExtensionCompose ( ...funcs : [ Config ] | StoreEnhancer [ ] ) {
645+ ...funcs : [ Config ] | StoreEnhancer < unknown > [ ]
646+ ) {
624647 if ( funcs . length === 0 ) {
625648 return __REDUX_DEVTOOLS_EXTENSION__ ( ) ;
626649 }
627650 if ( funcs . length === 1 && typeof funcs [ 0 ] === 'object' ) {
628651 return extensionCompose ( funcs [ 0 ] ) ;
629652 }
630- return extensionCompose ( { } ) ( ...( funcs as StoreEnhancer [ ] ) ) ;
653+ return extensionCompose ( { } ) ( ...( funcs as StoreEnhancer < unknown > [ ] ) ) ;
631654}
632655
633656window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ = reduxDevtoolsExtensionCompose ;
0 commit comments