美文网首页
Flow模块类型(Module Types)

Flow模块类型(Module Types)

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

模块类型(Module Types)

导入和导出类型

在Flow中,你可以导入导出类型别名,接口和类。

export.js

// @flow
export default class Foo {};
export type MyObject = { /* ... */ };
export interface MyInterface { /* ... */ };

import.js

// @flow
import type Foo, {MyObject, MyInterface} from './exports';

导入和导出值

Flow支持通过typeof导入和导出值的类型。

export.js

// @flow
const myNumber = 42;
export default myNumber;
export class MyClass {
  // ...
}

import.js

// @flow
import typeof myNumber from './exports';
import typeof {MyClass} from './exports';

就像其他类型的导入,这个代码将被编译器剥离,不会增加对其他模块的依赖。

相关文章

网友评论

      本文标题:Flow模块类型(Module Types)

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