javascript - 如何纠正流量警告: destructuring (Missing annotation)

标签 javascript reactjs react-native flowtype

我正在编写一个小型 React Native 应用程序,并且正在尝试使用 Flow,但我无法在任何地方真正获得有关它的正确教程。

我不断收到错误:关于此代码第一行中的 ({ station })解构(缺少注释):

const StationDetail = ({ station }) => {
  const {
    code,
    label,
  } = station;

station 是一个 json 响应codelabel 是里面的 string那个json

如何修复错误/警告?

最佳答案

我会把它写成

type StationType = {
  code: String,
  label: String,
}

function StationDetail({ station } : {station : StationType}) => {
  const {
    code,
    label,
} = station;

需要声明函数接受的对象参数的类型。

关于javascript - 如何纠正流量警告: destructuring (Missing annotation),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41443242/

相关文章:

javascript - 确定 span 元素的位置以实现 float div 的绝对定位

javascript - 添加到节点的禁用选项无法与 vuetify 一起使用

reactjs - 为 `match` 连接 React Router 和 TypeScript

javascript - React/Axios 发送无限数量的请求

javascript - native react : How to stop child component rerendering on state change?

ios - React Native 独立 View 组件可通过 FlatList 滚动?

javascript - Ember : What is the meaning of re-render in ember js?

javascript - 如何在 Material UI React 中的 DatePicker 中格式化 get 和格式化 Date

android - Jest testing::测试失败并且错误路由到\react-native-vector-icons

javascript - 使用 jQuery 查找行索引