i try to extend a React Component Class with generic Parameters but I cannot get it working. According to the TypeScript Docs and this TypeScript Class Generic Parameter Constraints, and this extending a class with a generic T I ended up in the following (not working) code:
Base Class:
class BaseView<P, S> extends React.Component<P, S> {
public constructor(props: P, state: S) {
super(props, state);
}
}
const mapStateToProps = store => {
console.log('store', store);
return {
store
};
};
function mapDispatchToProps(dispatch) {
console.log('dispatch', dispatch);
return {
};
}
export default connect(mapStateToProps, mapDispatchToProps)((BaseView as any));
export function subclass<P, S>(c): BaseView<P, S> {
return c;
}
The class which extends the Base Class:
I tried different ways, using the factory like this:
export class Documents extends subclass(BaseView)<DocumentsProperties, DocumentsState> {
// this leads into ""BaseView<{}, {}>" is no constructor function type
or without using the factory:
export class Documents extends BaseView<DocumentsProperties, DocumentsState> {
// no base constructor has the specified number of type arguments
I also tried out several other ways but i feel like i was programming for the first time of my life....I cannot get it running for multiple Parameters. What am I missing here?
greetings Messerbill
`. I don't understand why the latter doesn't work, though. I can't reproduce your error in the [Playground](http://www.typescriptlang.org/play//). Can you reproduce the error in a self-contained (no libraries) example? If not you'll have to wait for someone with react installed in their environment
– jcalz Oct 11 '18 at 16:40})` for both `c` and the return type.
– MinusFour Oct 11 '18 at 17:29