我有一个扩展另一个组件的组件类,我试图弄清楚如何覆盖我继承的状态类型。
下面是一个例子:
class MyComponent extends React.Component<SomeProps, SomeState> {
// ...
}
class ExtendedComponent extends MyComponent {
// How to overwrite SomeState?
// This component needs to store a different model of state.
}
Run Code Online (Sandbox Code Playgroud)
我需要ExtendedComponent为其使用不同interface的state,但我无法弄清楚如何实现这一点。
编辑:现在去某个地方!
但是,现在Parent充斥着与状态修改有关的各种错误。这是我到目前为止所得到的:
interface ParentProps {
a: string;
}
interface ParentState {
b: string;
}
class Parent<P, S> extends React.Component<ParentProps & P, ParentState & S> {
constructor(props) {
super(props);
// Type '{ b: "hello"; }' is not assignable to …Run Code Online (Sandbox Code Playgroud)