diff --git a/src/components/connect.tsx b/src/components/connect.tsx index a946a70db..5e318a5c4 100644 --- a/src/components/connect.tsx +++ b/src/components/connect.tsx @@ -305,6 +305,12 @@ export interface Connect { TOwnProps > + /** mapState and mapDispatch (nullish) */ + ( + mapStateToProps: MapStateToPropsParam, + mapDispatchToProps: null | undefined + ): InferableComponentEnhancerWithProps + /** mapState and mapDispatch (as an object) */ ( mapStateToProps: MapStateToPropsParam, diff --git a/test/typetests/connect-mapstate-mapdispatch.tsx b/test/typetests/connect-mapstate-mapdispatch.tsx index 946f62181..549119d0e 100644 --- a/test/typetests/connect-mapstate-mapdispatch.tsx +++ b/test/typetests/connect-mapstate-mapdispatch.tsx @@ -269,6 +269,40 @@ function MapStateAndDispatchObject() { const verify = } +function MapStateAndNullishDispatch() { + interface ClickPayload { + count: number + } + const onClick: ActionCreator = () => ({ count: 1 }) + const dispatchToProps = { + onClick, + } + + interface OwnProps { + foo: string + } + interface StateProps { + bar: number + } + + const mapStateToProps = (_: any, __: OwnProps): StateProps => ({ + bar: 1, + }) + + class TestComponent extends React.Component {} + + const TestDispatchPropsNull = connect(mapStateToProps, null)(TestComponent) + + const verifyNull = + + const TestDispatchPropsUndefined = connect( + mapStateToProps, + undefined + )(TestComponent) + + const verifyNonUn = +} + function MapDispatchFactory() { interface OwnProps { foo: string @@ -422,6 +456,33 @@ function MapStateAndDispatchAndMerge() { const verify = } +function MapStateAndMerge() { + interface OwnProps { + foo: string + } + interface StateProps { + bar: number + } + interface DispatchProps { + onClick: () => void + } + + class TestComponent extends React.Component {} + + const mapStateToProps = () => ({ + bar: 1, + }) + + const mergeProps = (stateProps: StateProps, _: null, ownProps: OwnProps) => ({ + ...stateProps, + ...ownProps, + }) + + const Test = connect(mapStateToProps, null, mergeProps)(TestComponent) + + const verify = +} + function MapStateAndOptions() { interface State { state: string