How do you export a Flow type definition that is imported from another file?

ide picture ide · Sep 16, 2015 · Viewed 15.9k times · Source

Given a type definition that is imported from another module, how do you re-export it?

/**
 * @flow
 */

import type * as ExampleType from './ExampleType';

...

// What is the syntax for exporting the type?
// export { ExampleType };

Answer

Gabe Levi picture Gabe Levi · Sep 22, 2015

The simplest form of this question is "how do I export a type alias?" and the simple answer is "with export type!"

For your example, you can write

/**
 * @flow
 */

import type * as ExampleType from './ExampleType';
export type { ExampleType };

You may ask "why is ExampleType a type alias?" Well, when you write

type MyTypeAlias = number;

You are explicitly creating the type alias MyTypeAlias which aliases number. And when you write

import type { YourTypeAlias } from './YourModule';

You are implicitly creating the type alias YourTypeAlias which aliases the YourTypeAlias export of YourModule.js.