Flowtype-Flowtype可以自动注释变量的类型吗? [英] Flowtype - Can flowtype automatically annotate the variables' type?

查看:58
本文介绍了Flowtype-Flowtype可以自动注释变量的类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了flowtype的文档,但是找不到与类型推断有关的内容,例如:

I have searched the doc of flowtype but I can not find something relevant to type inference, for example:

function add(x){
  return x+10;
}

使用flowtype后,它将变为:

after using flowtype, it becomes:

function add(x:string){
   return x+10;
}

就像jsnice.

推荐答案

flow suggest确实是可行的方法.通常,它无法推断导出函数的输入类型(只能在文件中本地使用未导出的函数),但可以填写所有函数的输出类型,局部变量的类型等.

flow suggest is indeed the way to go. In general it cannot infer input types for functions that are exported (only un-exported functions used locally in your file), but it can fill in output types of all functions, the types of local variables, etc.

还请注意,Flow不会推断多态类型.

Also note that Flow doesn't infer polymorphic types.

这篇关于Flowtype-Flowtype可以自动注释变量的类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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