【问题标题】:IDE doesn't recognize method using JSDocIDE 无法识别使用 JSDoc 的方法
【发布时间】:2017-02-14 08:15:46
【问题描述】:

我有一个定义如下的函数。

/**
 * @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 知道 sayIt 方法可用于 hello 对象,并且它将 words 参数作为字符串接收。目前它知道sayIt是一个方法但不知道它与hello对象相关联,所以我没有得到任何自动完成帮助。

【问题讨论】:

标签: javascript function webstorm jsdoc


【解决方案1】:

即使您的代码没有 JSDOC,Webstorm 也应该能够为您提供自动更正功能。

检查您是否拥有module.exports = hello 而不是module.exports = hello()

如果此建议不起作用或不适用,我建议重构您的代码

我建议你这样做。

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

【讨论】:

    猜你喜欢
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    • 2020-04-05
    • 2017-12-26
    • 1970-01-01
    • 2016-09-02
    相关资源
    最近更新 更多