Nullish mapDispatchToProps causes Typescript Issues
See original GitHub issueWhat 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" />
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:
- Created a year ago
- Comments:11 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m sorry, I missed the CodeSandbox and was trying just with the code you had posted into this issue.
@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.