I am learning react and typescript with redux. I have a child component like this:
import ...
interface MainTestProps {
loadData: () => () => void,
students: StudentsModel[],
state: string,
errorMessage?:string
}
interface MainTestState {
}
class MainTest extends React.Component<MainTestProps,MainTestState>{
constructor(props: MainTestProps, state: MainTestState){
super(props,state);
}
.... rest of component
const mapStateToProps = (state:AppState, ownProps: MainTestProps)=> {
return {
students: [],
state: 'INIT',
errorMessage:''
}
}
const mapDispatchToProps = (dispatch: any) => {
return {
loadData: () => dispatch(actionFetchStudents())
}
}
export default connect(mapStateToProps,mapDispatchToProps) (MainTest);
Why if I call this component i receive the error Type '{}' is missing the following properties from type 'Readonly & MainTestProps>': loadData, students, state ts(2739). I mean I do not want to pass properties, I am using redux!!! Is there a bug in the typescript redux library or why I have to pass data or is my declaration of mapStateToProps wrong an I have to obmit the parameter ownProps.
Thank you all Arnold