// componet A
interface IPropsA {
propsForA: boolean;
}
interface IStateA {
isSleeping: boolean;
};
class A<P extends IPropsA, S extends IStateA> extends React.PureComponent<P, S> {
doStaff() {
this.setState({ isSleeping: false });
}
}
// componet B
interface IPropsB extends IPropsA {
propsForB: string;
};
interface IStateB extends IStateA{
isWorking: boolean;
};
class B extends A<bProps, bState> {
doStaff() {
this.setState({ isSleeping: false, isWorking: true });
}
}
ts编译器显示错误
Class 'A<P, S>' incorrectly extends base class 'PureComponent<P, S>'.
Types of property 'state' are incompatible.
Type 'IStateA' is not assignable to type 'Readonly<S>'.
在IStateB中使用额外属性扩展组件A的正确方法是什么,因此组件B可以工作?
我的目标是继承组件A所拥有的每一件事,并在B中扩展更多功能。