模块类型(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';
就像其他类型的导入,这个代码将被编译器剥离,不会增加对其他模块的依赖。