如何纠正流量警告:解构(缺少注释) [英] How to correct flow warning: destructuring (Missing annotation)

查看:89
本文介绍了如何纠正流量警告:解构(缺少注释)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个小型的React Native应用程序,我正在尝试使用Flow,但我无法在任何地方获得适当的教程。

I'm writing a small React Native app and I'm trying to use Flow, but I can't really get a proper tutorial about it anywhere.

我一直收到错误: destructuring(Missing annotation)关于({station})的第1行代码:

I keep getting the error: destructuring (Missing annotation) about the ({ station }) in the 1st line of this code:

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

station 是一个 json响应代码标签字符串里面那个 json

station is a json response and code and label are strings inside that json.

如何修复错误/警告?

推荐答案

我会把它写成

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

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

必须声明函数接受的对象参数的类型。

It's necessary to declare the type of the object parameter that the function accepts.

这篇关于如何纠正流量警告:解构(缺少注释)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆