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';
// ...
};
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?

Things that I tried:
- Remove
@param {String} [options.foo]
@param {?String} [options.foo]
@param {String} options.foo
if (!options) options = {foo: 'bar'};
- The last two combined.
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.
I'm using WebStorm 7.0.
Webstorm's documentation links to jsdoc 3. With jsdoc 3, I would document your object like this:
@param {{foo: string}} options
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.
来源:https://stackoverflow.com/questions/20235179/attribute-on-options-parameter-with-jsdoc-in-webstorm-unresolved-variable