React
コンポーネントから継承し、新しいProps
を定義します。そのような何か(Bar
とエラーの多くを持って、完全に間違っている必要があります):flowtype:継承と総称
// @flow
class Component<Props> {
props: Props;
constructor(props: Props) {
this.props = props;
}
}
type FooProps = {
x: number;
}
class Foo extends Component<FooProps> {
_render(value: string) {
return `hello, ${value}`;
}
render() {
return this._render(`${this.props.x}`);
}
};
type BarProps = {
x: number;
y: number;
}
class Bar extends Foo<BarProps> {
render() {
return this._render(`${this.props.x} ${this.props.y}`);
}
}
const foo: Foo = new Foo({x: 1});
const bar: Bar = new Bar({x: 1, y: 2});
? (それが重要であれば、Reactコンポーネントの文脈で)。
フロー0.57.2
を使用し、16.0.0
と反応させます。新しいを作成
継承ではどういう意味ですか? 'React'の場合、継承はコンポーネントをタイプするときに役割を果たしません。 'PropType'と同じように' props'を入力するだけです。 –
つまり 'Bar'は' Foo'を拡張し、 'Bar'は' props'のタイプを変更します。もう一度考えてみよう... –