在带有流类型注释的js上使用jsdoc [英] Use jsdoc on js with flow type annotations

查看:75
本文介绍了在带有流类型注释的js上使用jsdoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When trying to process js sources with flow type annotations the jsdoc parser failes to understand the enhanced syntax! Is there a way to use jsdoc in js sources that have been enhanced with flow type annotations or what is the recommended way to generate documentation from type annotated js?

推荐答案

您可以使用babel与 strip-流式转换并使用 jsdoc-babel

You could use babel with strip-flow-types transform and use jsdoc-babel.

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

First, you need to install babel and related packages and jsdoc-babel on top of jsdoc. Then, create a jsdoc-conf.json file in your root directory containing something like this:

{
    "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或其他巴贝尔插件。希望这会有所帮助!

You can use any valid babel setup with jsdoc-babel under "babel" that is applied in addition to your .babelrc file. e.g. presets for ES2015 or other babel plugins. Hope this helps!

这篇关于在带有流类型注释的js上使用jsdoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆