【问题标题】:JSDoc when exporting a function constructor in node.js在 node.js 中导出函数构造函数时的 JSDoc
【发布时间】:2016-08-26 09:31:00
【问题描述】:

我刚刚开始将一些 JSDoc cmets 添加到我一直在处理的代码库中,在大多数情况下这似乎可行,但有一个领域给我带来了一些困难。

如果我在一个文件中描述一个函数构造函数,然后在 module.exports 上导出它,当我稍后 require() 该模块时,我没有得到关于该类型的文档,并且推断的类型设置为 |exports。点击不会带我去任何地方。我目前有:

/**
 * Creates an instance of the StatusCodeErrorItem
 * @param {string} message The message for this error
 * @param {object} params The parameters that caused this error to occur
 * @alias lib/common/StatusCodeErrorItem.StatusCodeErrorItem
 * @returns {StatusCodeErrorItem}
 * @constructor
 */
function StatusCodeErrorItem(message, params) {
    this.message = message;
    this.params = params;
}

/**
 * Holds information about an error
 * @module lib/common/StatusCodeErrorItem
 */
module.exports = StatusCodeErrorItem;

在使用它的文件中:

var StatusCodeErrorItem = require('./StatusCodeErrorItem');

此时我认为我可以按 f1 来调出内联文档,并查看该文件中描述的 StatusCodeErrorItem 的定义。但相反,我只看到:推断类型 StatusCodeErrorItem|exports

网络风暴 9 Node.js 0.10.36(我知道两者都很旧)

对我做错了什么有什么想法吗?我所追求的甚至可能吗?我的版本是否太旧了?

干杯

【问题讨论】:

    标签: node.js webstorm jsdoc


    【解决方案1】:

    Webstorm 2016.1.1 解决了这个问题。下面的 JSDoc 被正确分配给由 require 引入的类型。我现在会缠着人们给我弄一个新的许可证。

    'use strict';
    
    /**
     * Creates an instance of the StatusCodeErrorItem
     * @memberof common
     * @constructor
     * @classdesc A class for holding information about an error. The params object allows the tracking of the function
     *  parameters that caused the error, but should not be used to store large objects.
     * @description Creates an instance of the StatusCodeErrorItem with the given message and optional params object
     * @param {string} message The message for this error
     * @param {object} [params] The parameters that caused this error to occur
     * @returns {StatusCodeErrorItem}
     * @see {@link module:lib/common/StatusCodeError.StatusCodeError|StatusCodeError}
     */
    function StatusCodeErrorItem(message, params) {
        this.message = message;
        this.params = params;
    }
    
    /**
     * Surfaces a class that holds information about an error
     * @module lib/common/StatusCodeErrorItem
     */
    module.exports = StatusCodeErrorItem;
    

    【讨论】:

      猜你喜欢
      • 2015-04-06
      • 2013-12-09
      • 2013-06-12
      • 1970-01-01
      • 2015-02-10
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      相关资源
      最近更新 更多