gpt4 book ai didi

flowtype - 流类型 - 生成 Libdef

转载 作者:行者123 更新时间:2023-12-04 08:47:44 24 4
gpt4 key购买 nike

我正在使用 Flow 来帮助创作一个 JS 项目。如果我想提供libdef file 为了补充它,我是否需要手动创建它,或者我是否能够执行一些我不知道的魔法命令,这将为我生成 lib def?

类似 $ flow-typed doyourmagic会好的。

编辑:

找到这个 https://stackoverflow.com/a/38906578/192999

其中说:

There's two things:

If the file is owned by you (i.e. not a third party lib inside node_modules or such), then you can create a *.js.flow file next to it that documents its exports.

If the file is not owned by you (i.e. third party lib inside node_modules or such), then you can create a libdef file inside flow-typed/name-of-library.js

For .js.flow files you write the definitions like this:


// @flow 
declare module.exports: { ... }

For libdef files you write the definitions like this:


declare module "my-third-party-library" {   declare module.exports: {... } }

对于我的问题,我属于“归你所有”阵营。

我想我很困惑:
  • 我如何编写这些文件。
  • 我如何/在哪里发布这些文件以将其打包以供另一个项目引用。

  • 另外,为什么我需要手动创建 .js.flow 文件?这不能神奇生成吗?也许这是 future 的意图,但尚未实现。

    最佳答案

    我找到了一个不错的 guide展示了如何将流程代码与编译后的代码打包在一起。所以:

  • 您不必编写自己的 libdef,您可以使用整个流程源代码。如果你想要一个只有类型声明的定义,你可以查看 flow gen-flow-files ,尽管这仍然是实验性的并且可能会失败。
  • 您可以将它们打包为 *.js.flow当您导入库时,流程检查器会自动选择这些。
  • 关于flowtype - 流类型 - 生成 Libdef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43235276/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com