流类型注释和有效的JavaScript源 [英] Flow type annotations and valid JavaScript source

查看:80
本文介绍了流类型注释和有效的JavaScript源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩Facebook新的Flow Type检查系统。

I'm playing with Facebook's new Flow Type checking system.

Flow,遇见Underscore 似乎他们更改了这个JavaScript代码

In Flow, meet Underscore it appears that they change this JavaScript code

var root = this;

进入此

var root: any = this;

但这不再是有效的JavaScript,对吧?我理解为什么外部接口文件很有用,但是如何将类型注释直接添加到有效的JavaScript源中?

But this is no longer valid JavaScript, right? I understand why external Interface files would be useful, but how are type annotations added directly into valid JavaScript sources?

以前,Google Closure编译器和JS注释中使用的其他项目。

Previously, Google Closure compiler and other projects used on JS comments.

推荐答案

从Flow 0.4.0开始,您可以将Flow语法放入注释中。这解决了您的问题。所以你的例子看起来像:

As of Flow 0.4.0 you are able to put the Flow syntax into the comments. This solves your issue. So your example would look like:

var root/*: any*/ = this;

这会产生有效的JavaScript语法,无需转换代码。

This results in valid JavaScript syntax and there is no need to transpile your code.

可在此处找到更多详细信息:
http://flowtype.org/blog/2015/02/20/Flow-Comments.html

Further details can be found here: http://flowtype.org/blog/2015/02/20/Flow-Comments.html

这篇关于流类型注释和有效的JavaScript源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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