czerny
czerny

Reputation: 16644

Exporting Flow type in CommonJS?

Is it possible to export and import Flow type definitions in CommonJS world similarly to ES6 like type imports/exports?

Upvotes: 6

Views: 802

Answers (1)

Ross Allen
Ross Allen

Reputation: 44880

There is no CommonJS-style require for Flow, but Flow's import type/export type syntax can be used alongside CommonJS require calls.

Though the syntax looks similar, import type and export type are not actual JavaScript import/export statements. They must be stripped from your code before your code can be run in current browsers. If you use Babel to compile your code, for example, you use the transform-flow-strip-types plugin to strip Flow types and type imports/exports.

Upvotes: 6

Related Questions