[英]IDE doesn't recognize method using JSDoc
我有一个定义如下的函数。
/**
* @type Object
* @return {typeof hello} hello
*/
function hello() {
/**
* Prints some words
* @param {string} words - words to print
* @returns {string} words you said
*/
function sayIt(words) {
console.log(words);
return 'You said: ' + words;
}
return {
sayIt: sayIt
}
}
我想要这样,当我hello.
我的IDE会告诉我说方法sayIt
可用,并且它将参数words
作为字符串。
此功能已作为模块加载到云系统中,并且可以从另一个脚本中调用它的唯一方法是导入hello
模块并像hello.sayIt('hello')
一样使用它。 因此,基本上,我想知道是否有一种格式化JSDoc的方法,以便我的IDE知道hello
对象可以使用sayIt
方法,并且它将words
参数作为字符串接收。 目前,它知道sayIt
是一种方法,但不知道它与hello
对象相关联,因此我没有得到任何自动完成帮助。
即使您的代码中没有JSDOC,Webstorm也应该能够为您提供自动更正。
检查您是否具有module.exports = hello
而不是module.exports = hello()
如果此建议不起作用或不适用,建议您重构代码
我建议您改为这样做。
return {
sayIt: function(words) {
console.log(words);
return 'You said: ' + words;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.