javascript - 反应全局声明变量得到流类型错误
问题描述
type Props = {
checkedItems:any
};
class MyApp extends Component<Props> {
constructor(props) {
super(props);
this.checkedItems = [];
}
}
在这里,我使用 Flow 对 react 类组件进行类型检查。当我使用npm run flow运行此文件时,我收到错误,例如无法将数组文字分配给,this.checkedItems
因为[1]checkedItems
中缺少属性。MyApp
有人可以告诉我我应该怎么做才能解决流量错误
解决方案
跑步者是正确的,checkedItems
类上没有定义属性。通过Props
作为类型传递给Component
类,您只需定义props
类型,您需要checkedItems
自己在类上定义。
class MyApp extends Component<{}> {
checkedItems: any;
constructor(props) {
super(props);
this.checkedItems = [];
}
}
推荐阅读
- node.js - csurf 中间件如何验证令牌?
- swift - 在 iOS 13 上清除SelectionOnViewWillAppear
- ios - {N} 6 打破 iOS 上的谷歌地图信息窗口
- c# - 在获取 HTTP 请求后,对 JSON 的 LINQ 查询在移动设备上不会返回任何值,但在 Windows 上会返回
- rxjs - 使用 RxJS 组合源事件和错误事件
- jquery - 在加载时逃脱挂起的jQuery?
- sql - SQL 查询以获取许多表中的最后更改
- python - 如何读取一组 .csv 文件,每个文件只保留一个特定列
- wordpress - 如何为特定类别创建元框 wordpress?
- powershell - 如何在参数名称中使用变量