如何使用JSDOC3来记录枚举常量

ASA*_*SA2 5 javascript enums jsdoc jsdoc3

我们正在使用JSDOC来记录面向客户端的SDK,我们很难让它识别我们的'枚举'(即常量).我们应该使用哪些标签让JSDOC在文档中提取它?这是一个示例:

/**
* @module Enum
*/
export namespace {

    /**
    * @enum WidgetType {string}
    */
    Enum.WidgetType = {
        /** Dashboard */
        Dashboard: 'dashboard',
        /** Form */
        Form: 'entityeditform',
        /** Report */
        Report: 'report'
    };
}
Run Code Online (Sandbox Code Playgroud)

以下是代码中使用"枚举"的方法:

app.widget({ id: 'account_entityform', type: Enum.WidgetType.Form }).add();
Run Code Online (Sandbox Code Playgroud)

我们如何用JSDOC记录这个?

Tod*_*odd 5

我看到这篇旧帖子有评论要求更多澄清。我只是从上面的内容中弄清楚了这一点,并且可以作为示例分享我的想法。登陆此页面搜索相同内容的人可能会发现这很有用。

/**
 * The color of a piece or square.
 * @readonly
 * @enum {number}
 * @property {number} WHITE color for a white square or piece.
 * @property {number} BLACK color for a black square or piece.
 */
export const Color = { WHITE: 0, BLACK: 1 }

/** 
 * Each member is an enumeration of direction offsets used to index into the 
 * lists of horzontal, vertical, and diagonal squares radiating from a
 * given Square object. Only useful internally for initialization or externally
 * for test.
 * @package
 * @type {object}
 * @readonly
 * @property {enum} Cross an enumeration of vert and horiz directions.
 * @property {number} Cross.NORTH north
 * @property {number} Cross.EAST  east
 * @property {number} Cross.SOUTH south
 * @property {number} Cross.WEST  west
 * @property {enum} Diagonal an enumeration of diagonal directions.
 * @property {number} Diagonal.NORTHEAST northeast
 * @property {number} Diagonal.SOUTHEAST southeast
 * @property {number} Diagonal.SOUTHWEST southwest
 * @property {number} Diagonal.NORTHWEST northwest
 */
const Direction = {
    Cross: { 
        NORTH: 0, EAST: 1, SOUTH: 2, WEST: 3 
    },
    Diagonal: { 
        NORTHEAST: 0, SOUTHEAST: 1, SOUTHWEST: 2, NORTHWEST: 3 
    },
}
Run Code Online (Sandbox Code Playgroud)


ASA*_*SA2 3

在 StackOverflow 上查看这篇文章后,我能够使用以下命令来实现此功能:

    /**
    * @typedef FieldType
    * @property {string} Text "text"
    * @property {string} Date "date"
    * @property {string} DateTime "datetime"
    * @property {string} Number "number"
    * @property {string} Currency "currency"
    * @property {string} CheckBox "checkbox"
    * @property {string} ComboBox "combobox"
    * @property {string} Dropdownlist "dropdownlist"
    * @property {string} Label "label"
    * @property {string} TextArea "textarea"
    * @property {string} JsonEditor "jsoneditor"
    * @property {string} NoteEditor "noteeditor"
    * @property {string} ScriptEditor "scripteditor"
    * @property {string} SqlEditor "sqleditor"
    */
Run Code Online (Sandbox Code Playgroud)

  • 有点不清楚,因为您的答案与原始问题中的代码片段不对应 (8认同)
  • @ASA2我目前面临同样的问题;但是,我没有得到你的例子。您能详细说明一下并提供一个完整的示例吗?那将是非常友善的。 (2认同)