@@ -11,7 +11,13 @@ import type { Store, AnyAction } from 'redux'
11
11
import type { SelectorFactory } from '../connect/selectorFactory'
12
12
import { createSubscription , Subscription } from '../utils/Subscription'
13
13
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
14
- import type { DispatchProp , Matching , GetProps } from '../types'
14
+ import type {
15
+ DispatchProp ,
16
+ Matching ,
17
+ GetProps ,
18
+ AdvancedComponentDecorator ,
19
+ ConnectedComponent ,
20
+ } from '../types'
15
21
16
22
import {
17
23
ReactReduxContext ,
@@ -183,16 +189,7 @@ export interface ConnectAdvancedOptions {
183
189
pure ?: boolean
184
190
}
185
191
186
- interface AnyObject {
187
- [ x : string ] : any
188
- }
189
-
190
- export default function connectAdvanced <
191
- S ,
192
- TProps ,
193
- TOwnProps ,
194
- TFactoryOptions extends AnyObject = { }
195
- > (
192
+ function connectAdvanced < S , TProps , TOwnProps , TFactoryOptions = { } > (
196
193
/*
197
194
selectorFactory is a func that is responsible for returning the selector function used to
198
195
compute new props from state, props, and dispatch. For example:
@@ -236,12 +233,19 @@ export default function connectAdvanced<
236
233
) {
237
234
const Context = context
238
235
236
+ type WrappedComponentProps = TOwnProps & ConnectProps
237
+
238
+ /*
239
239
return function wrapWithConnect<
240
- WC extends React . ComponentClass <
241
- Matching < DispatchProp < AnyAction > , GetProps < WC > > ,
242
- any
240
+ WC extends React.ComponentType<
241
+ Matching<DispatchProp<AnyAction>, GetProps<WC>>
243
242
>
244
243
>(WrappedComponent: WC) {
244
+ */
245
+ const wrapWithConnect : AdvancedComponentDecorator <
246
+ TProps ,
247
+ WrappedComponentProps
248
+ > = ( WrappedComponent ) => {
245
249
if (
246
250
process . env . NODE_ENV !== 'production' &&
247
251
! isValidElementType ( WrappedComponent )
@@ -487,7 +491,14 @@ export default function connectAdvanced<
487
491
// If we're in "pure" mode, ensure our wrapper component only re-renders when incoming props have changed.
488
492
const _Connect = pure ? React . memo ( ConnectFunction ) : ConnectFunction
489
493
490
- const Connect = _Connect as typeof _Connect & { WrappedComponent : WC }
494
+ type ConnectedWrapperComponent = typeof _Connect & {
495
+ WrappedComponent : typeof WrappedComponent
496
+ }
497
+
498
+ const Connect = _Connect as ConnectedComponent <
499
+ typeof WrappedComponent ,
500
+ WrappedComponentProps
501
+ >
491
502
Connect . WrappedComponent = WrappedComponent
492
503
Connect . displayName = ConnectFunction . displayName = displayName
493
504
@@ -496,17 +507,20 @@ export default function connectAdvanced<
496
507
props ,
497
508
ref
498
509
) {
510
+ // @ts -ignore
499
511
return < Connect { ...props } reactReduxForwardedRef = { ref } />
500
512
} )
501
513
502
- const forwarded = _forwarded as typeof _forwarded & {
503
- WrappedComponent : WC
504
- }
514
+ const forwarded = _forwarded as ConnectedWrapperComponent
505
515
forwarded . displayName = displayName
506
516
forwarded . WrappedComponent = WrappedComponent
507
517
return hoistStatics ( forwarded , WrappedComponent )
508
518
}
509
519
510
520
return hoistStatics ( Connect , WrappedComponent )
511
521
}
522
+
523
+ return wrapWithConnect
512
524
}
525
+
526
+ export default connectAdvanced
0 commit comments