question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nullish mapDispatchToProps causes Typescript Issues

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
phryneascommented, Jun 23, 2022

I’m sorry, I missed the CodeSandbox and was trying just with the code you had posted into this issue.

0reactions
marconi1992commented, Jun 23, 2022

@phryneas I updated the type tests in the project to reproduce the issue. https://github.com/reduxjs/react-redux/pull/1929

You will see the errors when running yarnpkg type-tests. Feel free to update the test case or point out if I’m doing something weird.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MapDispatchToProps causes Typescript Error in parent ...
Now in my parent component Typescript is telling me that it is missing the properties that I defined in PropsFromDispatch. This doesn't seem ......
Read more >
React-redux Continuing #21417, unable to pass props from ...
typescript @next does not fix the issue. Going off issue #21417. Code I define the component class and connect it as follows: export...
Read more >
Best Practices with React, Redux, and Typescript - XTIVIA
This article explores best practices for an app written with React, Redux, and Typescript.
Read more >
Typeerror: Cannot Read Property 'requestcontent' Of Undefined
Solution: The problem arises because we're attempting to map an undefined ... on such a variable causes the TypeError: Cannot read property of...
Read more >
Connect | React Redux
The mapStateToProps and mapDispatchToProps deals with your Redux store's ... Note: Creating new values in mergeProps will cause re-renders.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found