Correct type declaration for mapStateToProps of Redux connect (TypeScript 2) Correct type declaration for mapStateToProps of Redux connect (TypeScript 2) reactjs reactjs

Correct type declaration for mapStateToProps of Redux connect (TypeScript 2)


Well, seems like @types/react-redux accepts mapStateToProps to return exact the same type as took in. I wanted it to modify it for props during mapping like { states: AppStateTree }. Instead I've modified the state tree combineReducers({ states: myReducer }). So this code works fine:

interface IRootState {  state: IAppState;}const mapStateToProps = ( state: IRootState ) => state;const mapDispatchToProps = {  toggleOpenAddFeed};type IProps = IRootState & typeof mapDispatchToProps;class App extends React.Component<IProps, {}> { render() {    return (      <div className="main-wrapper">         <Mycomponent store={this.props} />      </div>    );  }}export default connect( mapStateToProps, mapDispatchToProps )( App );


ownProps doesn't have any type. You must give a type to it.

const mapStateToProps = ( state: IAppState, ownProps: any = {} )