Reputation: 2235
In WebStorm, PyCharm, and other JetBrains products you can use JSDoc comments to inform WebStorm that an object does have a specific property, thereby eliminating a warning.
Either @namespace
or @property
works well for plain object properties, but I can't find a JSDoc command that works for functions.
const query = require(...);
...
Object.keys(record)
.forEach(col => {
query.set(col, record[col]);
});
In the snippet above, .set(...)
is not recognized by WebStorm and produces an Unresolved function or method warning.
This is only a single example. My project uses multiple third-party libraries and many of those libraries have object methods that trigger the warning on use. There are no typescript definitions available for these libraries, and WebStorm's file analysis doesn't pick up on them.
I cannot modify the query object, nor can I change how it is imported. Is there a JSDoc comment I can add to eliminate the warning? I've tried multiple variations of @property, @param, @namespace, and @member.
I know that the warning can be disabled by using a // noinspection JSUnresolvedFunction
on the line directly above the use of the function, but this is an inferior solution. The JSDoc comments can be placed in multiple scopes, such as the start of the class or function definition. The JSDoc solution also improves readability and has meaning in other, non-JetBrains IDEs.
Upvotes: 1
Views: 1110
Reputation: 1238
JSDoc provides the way to explicitly annotate symbols with @type
So in your example it's could be:
/** @type {QueryObjectTypeDef} */
const query = require(...);
Also same effect could be achieved (tested in WebStorm) with inline annotation of function args:
forEach((/* ColTypeDef */ col) => {...})
Upvotes: 1