在 node.js 中导出函数构造函数时的 JSDoc

JSDoc when exporting a function constructor in node.js

我刚开始向我一直在处理的代码库添加一些 JSDoc 注释,在大多数情况下这似乎可行,但有一个方面给我带来了一些困难。

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

/**
 * 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(我知道都老了)

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

干杯

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;