constructor(props) {
super(props);
this.state = {
open: false,
};
this.input = null;
this.handleChange = this.handleChange.bind(this);
}
我在this.input = null
:
无法将
中null
分配给this.input
,因为属性input
是。{ 遗漏在MyComponent
[1]
找不到流量文档的答案。
答案 0 :(得分:0)
您可以在类定义的顶部定义实例属性的类型 -
class MyComponent extends React.Component {
input: string,
handleChange: (event: Object) => mixed,
constructor(props) {
super(props);
this.state = {
open: false,
};
this.input = null;
this.handleChange = this.handleChange.bind(this);
}
}