Module Types

Module Types

Importing and exporting types

It is often useful to share types in between modules (files). In Flow, you can export type aliases, interfaces, and classes from one file and import them in another.

exports.js

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

imports.js

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

Importing and exporting values

Flow also supports importing the type of values exported by other modules using typeof.

exports.js

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

imports.js

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

Just like other type imports, this code will be stripped away by a compiler and will not add a dependency on the other module.

© 2013–present Facebook Inc.
Licensed under the BSD License.
https://flow.org/en/docs/types/modules

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部