【问题标题】:js-doc / google-closure-compiler how to document passed enum object itself?js-doc / google-closure-compiler 如何记录传递的枚举对象本身?
【发布时间】:2017-03-24 16:39:49
【问题描述】:

例如

/**
 * Super my enum
 * @enum {number}
 */
var MyEnum = {
    ONE: 1,
    TWO: 2
};

/**
 * @param {what type is it?} enumObj
 */
function showEnum(enumObj) {
  console.log(enumObj);
}

//show the enum definition object
showEnum(MyEnum);

如何将参数类型描述为不是MyEnum 的值/实例,而是MyEnum 对象本身?

【问题讨论】:

    标签: javascript enums google-closure-compiler jsdoc


    【解决方案1】:

    我在 WebStorm 和 VSCode 中测试的自动补全解决方案是使用typeof MyEnum
    它仍然是无效的 JSDoc,但支持由 IDE 自动完成。

    /**
     * @param {typeof MyEnum} enumObj
     */
    function showEnum(enumObj) {
      console.log(enumObj);
    }
    

    【讨论】:

      【解决方案2】:

      使用!MyEnum,其中! 表示“非空”。

      /**
      * @param {!MyEnum} enumObj
      */
      function showEnum(enumObj) {
        console.log(enumObj);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-27
        • 1970-01-01
        • 2012-10-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-06
        相关资源
        最近更新 更多