How to tell WebStorm the type of "this"
I am using the code inspector, along with jsdoc comments, to try to clean up my code.
I have some issues, because I haven't yet found any good documentation on jsDoc and how WebStorm code inspector uses it (pointers welcome).
I have the following code:
function makeForm(selector, options) {
//...
$('body').on('change', 'mytable :input', function() {
// Inspector complains "Argument type makeForm is not assignable to parameter type jElement"
});
//...
}
/**
* inputValue function
* @param {jElement} field
* @returns {string}
*/
function inputValue(field) {
//...
}
How do I tell WebStorm that the this parameter in the function is of type jElement?
请先登录再写评论。
Please can you provide the complete code snippet? I can understand nothing from your example.
Sorry, I left out the crucial function call:
function makeForm(selector, options) {
//...
$('body').on('change', 'mytable :input', function() {
inputValue(this); // Inspector complains "Argument type makeForm is not assignable to parameter type jElement"
});
//...
}
/**
* inputValue function
* @param {jElement} field
* @returns {string}
*/
function inputValue(field) {
//...
}
The simplest workaround is to prefix callback with JSDoc comment having @this tag
I've created WEB-18976 for it to work without @this tag, as it seems it should.
Thankyou Konstantin.
Were can I find documentation on the JSDoc tags supported by WebStorm, and what they do?
There is no such place specifically for WebStorm, but you may refer to usejsdoc.org and google closure compiler docs, we are trying to follow them.