从RN0.53.0开始React.Component支持携带两个类型的参数Props 与 State ,通过Component<Props>我们可以约束Props中属性的类型:
type Props = {
foo: number,
};
type State = {
bar: number,
};
class MyComponent extends React.Component<Props, State> {
state = {
bar: 42,
};
render() {
return this.props.foo + this.state.bar;
}
}