我想知道如何在WebStorm 11中正确使用JSDoc来标记node.js应用程序中的类和类型以获得代码完成等。
示例:
文件A:
function A(){
this.b = true;
}
A.prototype.doSth = function doSth() {
return !this.b;
}
module.export = new A();
文件B:
var foo = bar(); // returns type of A
现在我想为" foo。"完成代码,以便建议foo.b,foo.doSth,...
我尝试了很多JSDoc条目,比如@class,@ costructor,并使用@type {A}来定义foo类型
/* @type {A} */
var foo = bar();
但WebStorm无法识别类型A.它没有代码完成,而且Ctrl +单击括号中的类型A表示"找不到声明转到"。
知道如何正确地做到这一点吗?
答案 0 :(得分:1)
好像我找到了解决方案。问题只是我用来标记变量类型的语法:
/**
* @class
*/
function A(){
this.b = true;
}
A.prototype.doSth = function doSth() {
return !this.b;
}
module.export = new A();
使用
/**
* @type {A}
*/
var foo = bar();
请注意注释语法的不同之处: 以前我试过用
/* @type {A} */
var foo = bar();
哪个不起作用。 @class
也可以与@constructor