I'm trying to specify the types of req and res, to get intellisense to work on the parameters as I'm trying to illustrate below, but I'm not sure how to accomplish it.
var http = require('http');
http.createServer(foo).listen(8081);
/**
* @? ? ?
*/
function foo(req, res) {
req.<intellisense context menu>
}
I've looked through some of the documentation at https://github.com/Microsoft/TypeScript/wiki/JavaScript-Language-Service-in-Visual-Studio and https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript, but don't know if this is even possible. I'm a beginner at javascript, can somebody point me in correct direction?
Bonus question: How can I make this work also if foo
is in another module/file, and that module doesn't in itself require('http')
?
To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.
This is a very old question but since I stumbled upon it while looking for the same thing, here is an answer:
You need to specify the type of the parameter after @param
in curly brackets like this:
/**
*
* @param {XMLHttpRequest} req Some XMLHttpRequest
* @param {string} res (Let's suppose res is a string)
*/
function foo(req, res) {
req.<intellisense context menu appears>
}
More info (with a nice video demonstration) is available in Visual Studio Code documentation:
https://code.visualstudio.com/docs/languages/javascript#_js-doc-support
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With