在带有流类型注释的js上使用jsdoc

Use jsdoc on js with flow type annotations

当尝试处理带有流类型注释的 js 源代码时,jsdoc 解析器无法理解增强的语法!有没有办法在已通过流类型注释增强的 js 源代码中使用 jsdoc,或者从类型注释的 js 生成文档的推荐方法是什么?

您可以将 babel 与 strip-flow-types transform and use jsdoc-babel 一起使用。

首先,你需要在jsdoc上安装babel及相关包和jsdoc-babel。然后,在您的根目录中创建一个 jsdoc-conf.json 文件,其中包含如下内容:

{
    "plugins": ["node_modules/jsdoc-babel"],
    "babel": {
        "presets": ["react"],
        "plugins": ["transform-react-jsx", "transform-flow-strip-types"]
    }
}

用法:jsdoc -c jsdoc-conf.json

除了 .babelrc 文件之外,您还可以在 "babel" 下使用任何有效的 babel 设置和 jsdoc-babel。例如ES2015 或其他 babel 插件的预设。希望这对您有所帮助!

刚开始使用 documentation.js。开箱即用地支持 JSdoc 和流。