【问题标题】:how to publish a flow-typed library with its own types如何发布具有自己类型的流类型库
【发布时间】:2021-01-25 14:27:46
【问题描述】:

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

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

dist 目录只包含转译文件。

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

【问题讨论】:

    标签: flowtype flow-typed


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 它实际上并没有工作 :( 我发现让它工作的唯一方法是 ysubg gen-flow-files 并强制将定义读入我的 .flowconfig 像这样 [libs] node_modules/<MY-LIB>/dist/index.js.flow 跨度>
    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 2016-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多