2017-02-13 56 views
0

我有一个如下所示的函数。IDE不识别使用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知道sayIt方法可用于hello对象,并且它将words参数用作字符串。目前它知道sayIt是一种方法,但不知道它与hello对象关联,所以我没有得到任何自动完成帮助。

+0

所以,你一直在说“IDE”,但你真正的意思是WebStorm,从标签判断。有关于如何在帮助中正确添加JSDoc的文档:https://www.jetbrains.com/help/webstorm/2016.3/creating-jsdoc-comments.html –

回答

0

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

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

如果此建议不工作或不适用,我会建议重构你的代码

我建议你这样做来代替。

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