枚举为JSDoc中的@param类型 [英] Enum as @param type in JSDoc

查看:1683
本文介绍了枚举为JSDoc中的@param类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在JSDoc @param 类型声明中使用枚举,如下例所示?

Is it possible to use an enum for the JSDoc @param type declaration like in the following example?

/**
 * @enum { Number }
 */
var TYPES = {
    TYPE_A: 1,
    TYPE_B: 2
}

/**
 * @param { TYPES } type
 */
function useTypesEnum( type ) {

}

如果我使用像Eclipse等IDE这样的JavaScript,那么应该没有警告提出?

If I use an IDE like Eclipse etc. for JavaScript, there should no warning be raised?

推荐答案

JsDoc注释对JavaScript代码没有影响。它影响的是一些旨在使用该信息的工具。使用JsDoc注释的两个工具是文档生成器和Google Closure Compiler。

JsDoc comments have no impact on JavaScript code. What it does influence is some tools designed to use that information. Two of the tools that work with JsDoc comments are the documentation generator and the Google Closure Compiler.

我对JsDoc3并不是特别熟悉,其中添加了@enum标签,但我认为它可以像任何其他类型一样工作。

I am not particularly familiar with JsDoc3, in which the @enum tag has been added, but i would assume it works just as any other type.

Closure Compiler也能正确识别枚举,您可以像在示例中提到的那样使用它,并获得编译器的所有好处(例如:类型检查)。

The Closure Compiler also recognizes the enum correctly and you can use it just like you mentioned in the example and get all the benefits of the compiler (ex: type checking).

这篇关于枚举为JSDoc中的@param类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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