【问题标题】:How To Use JSDOC3 To Document Enum Constants如何使用 JSDOC3 记录枚举常量
【发布时间】:2016-07-29 01:41:32
【问题描述】:

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

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

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

以下是“枚举”在代码中的使用方式:

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

我们如何用 JSDOC 记录这个?

【问题讨论】:

    标签: javascript enums jsdoc jsdoc3


    【解决方案1】:

    我看到这个旧帖子中有 cmets 要求更多澄清。我只是从上面想出来的,可以分享一下,作为一个例子,我想出了什么。登陆此页面并搜索相同内容的人可能会发现这很有用。

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

    【讨论】:

    • Readonly 不能这样工作,不幸的是,您必须将其附加到对象内的每个属性中。
    • 我注意到一些面向 JS 文档的工具对上述格式的支持不一致。所以它可能适用于某些人而不适用于其他人@basickarl
    【解决方案2】:

    在查看this article on 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"
        */
    

    【讨论】:

    • 有点不清楚,因为您的答案与原始问题中的代码 sn-p 不对应
    • @ASA2 我目前面临同样的问题;但是,我没有得到你的例子。你能详细说明一下并提供一个完整的例子吗?那将是非常友好的。
    猜你喜欢
    • 2014-04-10
    • 2010-10-07
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 2016-01-31
    • 2019-12-23
    • 2014-09-03
    • 2014-03-02
    相关资源
    最近更新 更多