I'm trying to use Generic interfaces for my classes. My Class has a generic Type which Extends an interface and a class variable with that Type. But as soon as I try to assign a value to that variable the compiler gives me an error.(Example: Class A)
When I don't extend the Generic Type it works. (Example: Class B)
//Generic Classes problem
interface MyStateInterface {
test?: number
}
class A<IState extends MyStateInterface> {
protected state: IState;
constructor() {
// Error here
this.state = {
test: 1
};
}
}
class B<IState extends MyStateInterface> {
protected state: MyStateInterface;
constructor() {
this.state = {
test: 1
};
}
}
Does anyone have a solution to this problem?