diff --git a/src/components/connect.tsx b/src/components/connect.tsx index d018fc0ed..aefe7a6dc 100644 --- a/src/components/connect.tsx +++ b/src/components/connect.tsx @@ -280,19 +280,25 @@ function connect< State = DefaultRootState >( mapStateToProps: MapStateToPropsParam -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps< + TStateProps & DispatchProp, + TOwnProps & ConnectProps +> /* @public */ function connect( mapStateToProps: null | undefined, mapDispatchToProps: MapDispatchToPropsNonObject -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps /* @public */ function connect( mapStateToProps: null | undefined, mapDispatchToProps: MapDispatchToPropsParam -): InferableComponentEnhancerWithProps, TOwnProps> +): InferableComponentEnhancerWithProps< + ResolveThunks, + TOwnProps & ConnectProps +> /* @public */ function connect< @@ -303,7 +309,10 @@ function connect< >( mapStateToProps: MapStateToPropsParam, mapDispatchToProps: MapDispatchToPropsNonObject -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps< + TStateProps & TDispatchProps, + TOwnProps & ConnectProps +> /* @public */ function connect< @@ -316,7 +325,7 @@ function connect< mapDispatchToProps: MapDispatchToPropsParam ): InferableComponentEnhancerWithProps< TStateProps & ResolveThunks, - TOwnProps + TOwnProps & ConnectProps > /* @public */ @@ -329,7 +338,7 @@ function connect< mapStateToProps: null | undefined, mapDispatchToProps: null | undefined, mergeProps: MergeProps -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps /* @public */ function connect< @@ -342,7 +351,7 @@ function connect< mapStateToProps: MapStateToPropsParam, mapDispatchToProps: null | undefined, mergeProps: MergeProps -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps /* @public */ function connect< @@ -354,7 +363,7 @@ function connect< mapStateToProps: null | undefined, mapDispatchToProps: MapDispatchToPropsParam, mergeProps: MergeProps -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps /* @public */ // @ts-ignore @@ -368,7 +377,10 @@ function connect< mapDispatchToProps: null | undefined, mergeProps: null | undefined, options: ConnectOptions -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps< + DispatchProp & TStateProps, + TOwnProps & ConnectProps +> /* @public */ function connect( @@ -376,7 +388,7 @@ function connect( mapDispatchToProps: MapDispatchToPropsNonObject, mergeProps: null | undefined, options: ConnectOptions<{}, TStateProps, TOwnProps> -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps /* @public */ function connect( @@ -384,7 +396,10 @@ function connect( mapDispatchToProps: MapDispatchToPropsParam, mergeProps: null | undefined, options: ConnectOptions<{}, TStateProps, TOwnProps> -): InferableComponentEnhancerWithProps, TOwnProps> +): InferableComponentEnhancerWithProps< + ResolveThunks, + TOwnProps & ConnectProps +> /* @public */ function connect< @@ -397,7 +412,10 @@ function connect< mapDispatchToProps: MapDispatchToPropsNonObject, mergeProps: null | undefined, options: ConnectOptions -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps< + TStateProps & TDispatchProps, + TOwnProps & ConnectProps +> /* @public */ function connect< @@ -412,7 +430,7 @@ function connect< options: ConnectOptions ): InferableComponentEnhancerWithProps< TStateProps & ResolveThunks, - TOwnProps + TOwnProps & ConnectProps > /* @public */ @@ -427,7 +445,7 @@ function connect< mapDispatchToProps: MapDispatchToPropsParam, mergeProps: MergeProps, options?: ConnectOptions -): InferableComponentEnhancerWithProps +): InferableComponentEnhancerWithProps /** * Connects a React component to a Redux store. diff --git a/test/components/connect.spec.tsx b/test/components/connect.spec.tsx index 5b97021f9..324888b37 100644 --- a/test/components/connect.spec.tsx +++ b/test/components/connect.spec.tsx @@ -2179,10 +2179,6 @@ describe('React', () => { rtl.render( - {/*TODO: Since the connect type does not support this advanced usage, - we will ignore it for the time being and resolve it after merging connect and connectAdvanced - https://github.com/reduxjs/react-redux/pull/1781 */} - {/*// @ts-ignore */} @@ -2211,13 +2207,9 @@ describe('React', () => { const Decorated = decorator(Container) const store = createStore(() => expectedState) - rtl.render( - {/*TODO: Since the connect type does not support this advanced usage, - we will ignore it for the time being and resolve it after merging connect and connectAdvanced - https://github.com/reduxjs/react-redux/pull/1781 */} - {/*// @ts-ignore */} + {/*@ts-expect-error*/} ) @@ -2259,6 +2251,7 @@ describe('React', () => { const rendered = rtl.render( + {/*@ts-expect-error*/} ) @@ -2307,7 +2300,6 @@ describe('React', () => { ) } - const ConnectedComp2 = connect((state) => state)(Comp2) type Comp1TStatePropsType = Store1State1Type type Comp1NoDispatchType = NoDispatchType @@ -2354,6 +2346,12 @@ describe('React', () => { return state } } + const ConnectedComp2 = connect< + Store2State1Type, + unknown, + unknown, + Store2State1Type + >((state) => state)(Comp2) const store1 = createStore(reducer1) const store2 = createStore(reducer2) @@ -2361,10 +2359,6 @@ describe('React', () => { const tester = rtl.render( - {/*TODO: Since the connect type does not support this advanced usage, - we will ignore it for the time being and resolve it after merging connect and connectAdvanced - https://github.com/reduxjs/react-redux/pull/1781 */} - {/*// @ts-ignore */}