如何发布具有自己类型的流类型库



我已经在流中编写了一个index.js模块,我用Babel对其进行了转换,将其放在/dist目录中,并定义为package.json:中的主文件

{
"name": "my-lib",
"version": "0.9.0",
"description": "...",
"main": "dist/index.js",
...
}

CCD_ 3目录仅包含已传输的文件。

当我在另一个项目中使用它时,通过npm或yarn(yarn add <my-local-path-to-the-module>(导入,我可以导入到我的项目的模块中,但我丢失了原始的流定义(当然,babel剥离了它们(。我如何将流定义与传输文件关联起来,以便准备好使用模块及其流类型?

创建dist文件后,需要从源代码中创建关联声明文件。https://flow.org/en/docs/declarations/

所以最后你的dist-dir会有一个类似的文件结构

- dist
- index.js
- index.flow.js
- something.js
- something.flow.js
- dir1
file1.js
file1.flow.js

您可以使用https://github.com/Macil/flow-copy-source或https://github.com/lessmess-dev/gen-flow-files

最新更新