Skip to content

Commit 32e40e4

Browse files
authored
Merge pull request #1928 from marconi1992/fix/1927
2 parents 5082af7 + ff7d96b commit 32e40e4

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Diff for: src/components/connect.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ export interface Connect<DefaultState = unknown> {
305305
TOwnProps
306306
>
307307

308+
/** mapState and mapDispatch (nullish) */
309+
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
310+
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
311+
mapDispatchToProps: null | undefined
312+
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>
313+
308314
/** mapState and mapDispatch (as an object) */
309315
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
310316
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,

Diff for: test/typetests/connect-mapstate-mapdispatch.tsx

+61
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,40 @@ function MapStateAndDispatchObject() {
269269
const verify = <Test foo="bar" />
270270
}
271271

272+
function MapStateAndNullishDispatch() {
273+
interface ClickPayload {
274+
count: number
275+
}
276+
const onClick: ActionCreator<ClickPayload> = () => ({ count: 1 })
277+
const dispatchToProps = {
278+
onClick,
279+
}
280+
281+
interface OwnProps {
282+
foo: string
283+
}
284+
interface StateProps {
285+
bar: number
286+
}
287+
288+
const mapStateToProps = (_: any, __: OwnProps): StateProps => ({
289+
bar: 1,
290+
})
291+
292+
class TestComponent extends React.Component<OwnProps & StateProps> {}
293+
294+
const TestDispatchPropsNull = connect(mapStateToProps, null)(TestComponent)
295+
296+
const verifyNull = <TestDispatchPropsNull foo="bar" />
297+
298+
const TestDispatchPropsUndefined = connect(
299+
mapStateToProps,
300+
undefined
301+
)(TestComponent)
302+
303+
const verifyNonUn = <TestDispatchPropsUndefined foo="bar" />
304+
}
305+
272306
function MapDispatchFactory() {
273307
interface OwnProps {
274308
foo: string
@@ -422,6 +456,33 @@ function MapStateAndDispatchAndMerge() {
422456
const verify = <Test foo="bar" />
423457
}
424458

459+
function MapStateAndMerge() {
460+
interface OwnProps {
461+
foo: string
462+
}
463+
interface StateProps {
464+
bar: number
465+
}
466+
interface DispatchProps {
467+
onClick: () => void
468+
}
469+
470+
class TestComponent extends React.Component<OwnProps & StateProps> {}
471+
472+
const mapStateToProps = () => ({
473+
bar: 1,
474+
})
475+
476+
const mergeProps = (stateProps: StateProps, _: null, ownProps: OwnProps) => ({
477+
...stateProps,
478+
...ownProps,
479+
})
480+
481+
const Test = connect(mapStateToProps, null, mergeProps)(TestComponent)
482+
483+
const verify = <Test foo="bar" />
484+
}
485+
425486
function MapStateAndOptions() {
426487
interface State {
427488
state: string

0 commit comments

Comments
 (0)