简体   繁体   English

IDE无法识别使用JSDoc的方法

[英]IDE doesn't recognize method using JSDoc

I've got a function defined like the one below. 我有一个定义如下的函数。

/**
 * @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
    }
}

I would like it so that when I type hello. 我想要这样,当我hello. my IDE would tell me that the method sayIt is available and that it takes in the parameter words as a string. 我的IDE会告诉我说方法sayIt可用,并且它将参数words作为字符串。

This function is getting loaded as a module into a cloud system and the only way you can call it from another script is by importing the hello module and using it like hello.sayIt('hello') . 此功能已作为模块加载到云系统中,并且可以从另一个脚本中调用它的唯一方法是导入hello模块并像hello.sayIt('hello')一样使用它。 So basically I'm wondering if there is a way to format the JSDoc so that my IDE knows that the sayIt method is available to the hello object and that it takes in a words parameter as a string. 因此,基本上,我想知道是否有一种格式化JSDoc的方法,以便我的IDE知道hello对象可以使用sayIt方法,并且它将words参数作为字符串接收。 At present it knows that sayIt is a method but does not know that it is associated with the hello object, so I don't get any auto completion help. 目前,它知道sayIt是一种方法,但不知道它与hello对象相关联,因此我没有得到任何自动完成帮助。

Webstorm should be able to give you autocorrect even if you don't have JSDOC for your code. 即使您的代码中没有JSDOC,Webstorm也应该能够为您提供自动更正。

Check that you have module.exports = hello and not module.exports = hello() 检查您是否具有module.exports = hello而不是module.exports = hello()

If this suggestion does not work or does not apply, I would advise refactoring your code 如果此建议不起作用或不适用,建议您重构代码

I would recommend you do this instead. 我建议您改为这样做。

return {
  sayIt: function(words) {
    console.log(words);
    return 'You said: ' + words;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM