我刚刚开始在我一直在研究的代码库中添加一些JSDoc注释,但大多数情况下这似乎都有效,但是有一个方面给我带来了一些困难。
如果我在文件中描述一个函数构造函数,然后将其导出到module.exports上,当我稍后需要()该模块时,我没有得到关于该类型的文档,并且推断类型被设置为| 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
Webstorm 9 Node.js 0.10.36(我知道两者都老了)
对我做错了什么的想法?我甚至可能追求什么?我的版本太旧了吗?
干杯
答案 0 :(得分:0)
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;