reactjs - 如何用流描述类属性的类型?
问题描述
constructor(props) {
super(props);
this.state = {
open: false,
};
this.input = null;
this.handleChange = this.handleChange.bind(this);
}
我有这个错误this.input = null
:
无法分配给
null
,this.input
因为[1]input
中缺少属性MyComponent
在流文档上找不到答案。
解决方案
您可以在类定义的顶部定义实例属性的类型 -
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);
}
}
推荐阅读
- oracle - ODI KM 选项 - 来自 FLEX FIELD 的值
- scala - Scala 在无符号和有符号字节之间转换
- javascript - 如何在现有网站上添加 React Js?
- javascript - if (MageCustomer.name !== undefined) { 获取错误空值
- javascript - 在 javascript 文件中使用 javascript 编写 javascript 代码
- javascript - 如何在 ShaderMaterial 上获得正确的阴影
- r - 在 R 中使用 simr 包确认成功的“扩展”
- html - 在双滑块 HTML 组件中,单击 Internet Explorer 中无法识别的第一个元素
- swift - Swift - 弹出对话框禁用方向
- oracle - 像参数一样的甲骨文