I am looking to hook up React Redux to my component in typescript. I am using these docs as a template.
I have the following type defining the state I have in the Redux store (there is only one):
export interface rootState {
favourites: ImageThumbnail[]
}
My component:
...
interface StateProps {
favourites: NasaImageThumbnail[]
}
interface DispatchProps {
addFavourite: () => void
removeFavourite: () => void
}
interface OwnProps {
...
}
const mapState = (state: rootState) => ({
favourites: state.favourites
})
const mapDispatch = {
addFavourite: () => ({ type: 'ADD_FAVOURITE' }),
removeFavourite: () => ({ type: 'REMOVE_FAVOURITE' })
}
type combinedProps = StateProps & DispatchProps & OwnProps
//Component body
export default connect<StateProps, DispatchProps, OwnProps>(
mapState,
mapDispatch
)(Component)
mapState within the connect function is producing the following error:
No overload matches this call. The last overload gave the following error. Argument of type '(state: rootState) => { favourites: ImageThumbnail[]; }' is not assignable to parameter of type 'MapStateToPropsParam<StateProps, OwnProps, DefaultRootState>'. Type '(state: rootState) => { favourites: ImageThumbnail[]; }' is not assignable to type 'MapStateToPropsFactory<StateProps, OwnProps, DefaultRootState>'.