Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ export interface Connect<DefaultState = unknown> {
TOwnProps
>

/** mapState and mapDispatch (nullish) */
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
mapDispatchToProps: null | undefined
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>

/** mapState and mapDispatch (as an object) */
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = DefaultState>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
Expand Down
61 changes: 61 additions & 0 deletions test/typetests/connect-mapstate-mapdispatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,40 @@ function MapStateAndDispatchObject() {
const verify = <Test foo="bar" />
}

function MapStateAndNullishDispatch() {
interface ClickPayload {
count: number
}
const onClick: ActionCreator<ClickPayload> = () => ({ 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<OwnProps & StateProps> {}

const TestDispatchPropsNull = connect(mapStateToProps, null)(TestComponent)

const verifyNull = <TestDispatchPropsNull foo="bar" />

const TestDispatchPropsUndefined = connect(
mapStateToProps,
undefined
)(TestComponent)

const verifyNonUn = <TestDispatchPropsUndefined foo="bar" />
}

function MapDispatchFactory() {
interface OwnProps {
foo: string
Expand Down Expand Up @@ -422,6 +456,33 @@ function MapStateAndDispatchAndMerge() {
const verify = <Test foo="bar" />
}

function MapStateAndMerge() {
interface OwnProps {
foo: string
}
interface StateProps {
bar: number
}
interface DispatchProps {
onClick: () => void
}

class TestComponent extends React.Component<OwnProps & StateProps> {}

const mapStateToProps = () => ({
bar: 1,
})

const mergeProps = (stateProps: StateProps, _: null, ownProps: OwnProps) => ({
...stateProps,
...ownProps,
})

const Test = connect(mapStateToProps, null, mergeProps)(TestComponent)

const verify = <Test foo="bar" />
}

function MapStateAndOptions() {
interface State {
state: string
Expand Down