Skip to content

Nullish mapDispatchToProps causes Typescript Issues #1927

Closed
@marconi1992

Description

@marconi1992

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

  • React: 18.2.0
  • ReactDOM: 18.2.0
  • Redux: 4.2.0
  • React Redux: 8.0.2

What is the current behavior?

The connect HoC returns incorrect wrapped component prop types when passing null or undefined as mapDispatchToProps argument.

  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" />

image

Codesandbox: https://codesandbox.io/s/nullish-mapdispatchtoprops-q0eolm

What is the expected behavior?

If the connect HoC accepts null or undefined then it should infer the wrapped component props correctly

Which browser and OS are affected by this issue?

No response

Did this work in previous versions of React Redux?

  • Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions