使用Visual Studio代码在Node.JS中定义类型

问题描述 投票:0回答:1

当我使用Visual Studio Code编写node.js时,我得到了一些简单但非常有用的代码完成建议。例如,如果有回调,它会告诉我签名以及参数的类型。

我也想在自编代码中使用它。我能做些什么来使VS Code能够提供有意义的代码完成建议?

例如。使用快递,我得到的第三方库

enter image description here

但是在创建的方法中,我得到以下内容,而不是那么有用的弹出窗口。

enter image description here exports.getLastPrice =(market,callback)=> {... callback(result1,result2)}

我该怎么做才能得到关于我自己代码的好建议?谢谢!

编辑:用截图改进了问题

javascript node.js visual-studio-code
1个回答
3
投票

如果您提供,VS Code将使用Javascript文档字符串。例如:

/**
 * 
 * @param {string} param1 
 * @param {function(number, string):string} callback 
 */
function method1(param1, callback) {
    callback(result1, result2)
}

...给我代码完成帮助,如下所示:

enter image description here

Docstring在这里有详细记载:http://usejsdoc.org。这就是你要追求的吗?

© www.soinside.com 2019 - 2024. All rights reserved.