I\'m having some trouble figuring out how to properly type Redux containers.
Consider a simple presentational component that might look like this:
in
interface MyStateProps {
name: string;
selected: boolean;
}
interface MyDispatchProps {
onSelect: (name: string) => void;
}
interface MyOwnProps {
section: string;
}
// Intersection Types
type MyProps = MyStateProps & MyDispatchProps & MyOwnProps;
class MyComponent extends React.Component { }
function mapStateToProps(state: MyState): MyStateProps { }
function mapDispatchToProps(dispatch: IDispatch): MyDispatchProps { }
const MyContainer = connect(
mapStateToProps,
mapDispatchToProps
)(MyComponent);
You can use something use called Intersection Types https://www.typescriptlang.org/docs/handbook/advanced-types.html#intersection-types