Flow为什么需要注释导出功能的参数? [英] Why does Flow require annotation of parameter of exported function?

查看:56
本文介绍了Flow为什么需要注释导出功能的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码(

Following code (Flow playground):

/* @flow */

function a(p) {}
module.exports = a

引发异常

3: function a(p) {}
              ^ parameter `p`. Missing annotation

那是为什么?我希望参数p会自动采用类型any.

Why is that? I'd expect that type any would be automatically assumed for the parameter p.

推荐答案

来自文档:

模块边界

流程需要在模块的边界处添加注释.这使Flow能够独立地分析模块,从而提高了跨模块边界检查类型的性能.我们发现,这也有助于改善模块界面的自记录性质.

Module Boundaries

Flow requires annotations at the boundaries of modules. This allows Flow to analyze modules in isolation which improves the performance of checking types across module boundaries. We’ve found that this helps to improve the self-documenting nature of module interfaces as well.

这篇关于Flow为什么需要注释导出功能的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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