简体   繁体   English

如何使用 JSDOC3 记录枚举常量

[英]How To Use JSDOC3 To Document Enum Constants

We're using JSDOC to document our client-facing SDK and we're having difficult getting it to recognize our 'enums' (ie constants).我们正在使用 JSDOC 来记录我们面向客户端的 SDK,我们很难让它识别我们的“枚举”(即常量)。 Which tags should we use to get JSDOC to pick it up in the documentation?我们应该使用哪些标签来让 JSDOC 在文档中找到它? Here's a sample:这是一个示例:

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

    /**
    * @enum WidgetType {string}
    */
    Enum.WidgetType = {
        /** Dashboard */
        Dashboard: 'dashboard',
        /** Form */
        Form: 'entityeditform',
        /** Report */
        Report: 'report'
    };
}

Here's how the 'enums' are used in code:以下是在代码中使用“枚举”的方式:

app.widget({ id: 'account_entityform', type: Enum.WidgetType.Form }).add();

How can we document this with JSDOC?我们如何用 JSDOC 记录这个?

After reviewing this article on StackOverflow I was able to get this working using the following:在查看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"
    */

I see that there are comments to this old post asking for more clarification.我看到这篇旧帖子有评论要求更多说明。 I just figured it out from the above and can share, as an example, what I came up with.我只是从上面想出来的,可以分享,作为一个例子,我想出了什么。 People landing on this page searching for the same thing might find this useful.登陆此页面搜索相同内容的人可能会发现这很有用。

/**
 * 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 
    },
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM