美文网首页
Flow注释类型(Comment Types)

Flow注释类型(Comment Types)

作者: vincent_z | 来源:发表于2018-01-28 11:22 被阅读0次

注释类型(Comment Types)

Flow中的JavaScript使用一种特殊的注释语法。

Flow支持基于注释的语法,可以使用Flow而无需编译文件。

// @flow

/*::
type MyAlias = {
  foo: number,
  bar: boolean,
  baz: string,
};
*/

function method(value /*: MyAlias */) /*: boolean */ {
  return value.bar;
}

method({ foo: 1, bar: true, baz: ["oops"] });

这些注释使得Flow可以在纯JavaScript文件中存在。

注释类型语法

有两种主要的语法:类型包含与类型注释注解。

类型包含

使用::开始一段注释。

/*::
type Foo = {
  foo: number,
  bar: boolean,
  baz: string
};
*/

class MyClass {
  /*:: prop: string; */
}

上面这段代码在Flow中看起来是这样的:

type Foo = {
  foo: number,
  bar: boolean,
  baz: string
};

class MyClass {
  prop: string;
}

但是在JavaScript会屏蔽这些注释,所以看起来如下:

class MyClass {

}

你还可以使用flow-include的格式:

/*flow-include
type Foo = {
  foo: number,
  bar: boolean,
  baz: string
};
*/

class MyClass {
  /*flow-include prop: string; */
}
注释类型注解

使用:开始一段注释:

function method(param /*: string */) /*: number */ {
  // ...
}

相关文章

  • Flow注释类型(Comment Types)

    注释类型(Comment Types) Flow中的JavaScript使用一种特殊的注释语法。 Flow支持基于...

  • flow中文文档(二)

    Literal Types(绝对类型) flow不仅可以使用原始类型,还可以使用值作为类型注释。 多个值 Mixe...

  • 注释

    [TOC] 注释 类型: block comment: /* */ line comment: // 注释方...

  • 认识flow到入门

    认识Flow,Flow是一个类型检查器,加入类型注释的,即叫做覆盖类型 why Flow javascript是一...

  • 【DOM】Comment类型

    注释在DOM中是通过Comment类型来表示。 Comment节点特征 nodeType的值是8; nodeNam...

  • vue源码学习 --- flow(6)

    原文地址: https://flow.org/en/docs/types/classes/ 类和类类型 基本语法,...

  • Flow模块类型(Module Types)

    模块类型(Module Types) 导入和导出类型 在Flow中,你可以导入导出类型别名,接口和类。 expor...

  • Flow类类型(Class Types)

    类类型(Class Types) Flow中的JavaScript类同时作为一个值和一个类型存在。你可以像使用Fl...

  • Flow变量类型(Variable Types)

    变量类型(Variable Types) JavaScript有三种声明局部变量的方法: var - 声明一个变量...

  • Flow混合类型(Mixed Types)

    混合类型(Mixed Types) 单一类型 比如输入值只能是number 一组不同的类型: 比如输入值可以是st...

网友评论

      本文标题:Flow注释类型(Comment Types)

      本文链接:https://www.haomeiwen.com/subject/pemaaxtx.html