WebStorm中带有JSDoc的options参数的属性: [英] Attribute on options parameter with JSDoc in WebStorm: "Unresolved variable"
问题描述
我有一个带有jsdoc注释的函数,类似于我的代码中的以下内容:
I have a function with jsdoc comment that resembles the following in my code:
/**
* Foo function
* @param {Object} [options]
* @param {String} [options.foo]
*/
var foo = function (options) {
if (!options) options = {};
var foo = options.foo || 'foo';
// ...
};
我的IDE WebStorm将options.foo
标记为未解析的变量".如果删除jsdoc注释,警告将消失.如何以WebStorm获取提示并且不再显示此警告的方式记录此功能?
My IDE, WebStorm, marks options.foo
as an 'unresolved variable'. If I remove the jsdoc comment, the warning disappears. How do I document this function in a way that WebStorm gets the hint and no longer displays this warning?
我尝试过的事情:
- 删除
@param {String} [options.foo]
-
@param {?String} [options.foo]
-
@param {String} options.foo
-
if (!options) options = {foo: 'bar'};
- 最后两个加起来.
- Remove
@param {String} [options.foo]
@param {?String} [options.foo]
@param {String} options.foo
if (!options) options = {foo: 'bar'};
- The last two combined.
这是错误还是我错过了什么? WebStorm似乎确实了解options.foo
参数定义,因为if (!options) options = {foo: 42};
会发出警告,指出分配的类型不是字符串.
Is this a bug or am I missing something? WebStorm does seem to understand the options.foo
param definition, because if (!options) options = {foo: 42};
raises a warning that the assigned type is not a String.
我正在使用WebStorm 7.0.
I'm using WebStorm 7.0.
推荐答案
Webstorm的文档链接到jsdoc3.对于jsdoc 3,我将这样记录您的对象:
Webstorm's documentation links to jsdoc 3. With jsdoc 3, I would document your object like this:
@param {{foo: string}} options
您尝试执行此操作的方式意味着像function (options, options.foo)
这样的函数签名.
The way you were trying to do it implies a function signature like function (options, options.foo)
.
有关文档类型的信息,请此处.
Information about how to document types is available here.
这篇关于WebStorm中带有JSDoc的options参数的属性:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!