- Modern JavaScript Web Development Cookbook
- Federico Kereki
- 111字
- 2021-07-02 14:50:00
Using Flow types with modules
Exporting data types (including generics, interfaces, and so on) is quite similar to normal exports, except that you must include the word type. If you wanted to use the conversion type elsewhere, in the original module, you would add the following:
export type { conversion };
Correspondingly, wherever you wanted to import that type, you would add something like this:
import type { conversion } from "./module_conversions.js";
Note, however, an important detail: you cannot export or import data types in the same sentence in which you deal with standard JS elements: export and export type are distinct, separate statements, and so are import and import type.