The standard export default connect(...)(Component)
method does not work if you with for Component
to be generic
You must instead wrap the call to connect
in a function as so:
export default function connectedComponent<T>() {
return connect<StateProps, DispatchProps>(
mapStateToProps,
mapDispatchToProps
)(Component as new (props: ComponentProps<T>) => Component<T>);
}
Consumers must invoke the function with the generic before using them in code:
import ConnectedComponent from './ConnectedComponent'
const TypedConnectedComponent = ConnectedComponent<Type>();
...
<TypedConnectedComponent
...
/>