Howard
Howard

Reputation: 4604

Possible to give IntelliSense on specific type defined in third party library like express while writing node.js in vscode?

Let's say i am starting a new web app with express, and have vscode as my IDE for this nodejs project

Following code is working well with IntelliSense:

enter image description here

Once the handler is extracted, IntelliSense is gone:

enter image description here

I've tried jsdoc:

/**
 * 
 * @param {express.Request} req 
 * @param {express.Response} res 
 */
function test(req, res) {
  req. // no luck
}

Is there any way to have IntelliSense supported in this case?

Upvotes: 1

Views: 593

Answers (1)

Matt Bierner
Matt Bierner

Reputation: 65223

As of VS Code 1.20, this is a limitation when using require with JSDoc types (see this issue]

Workaround is to use import:

import * as express from 'express'

/**
 * 
 * @param {express.Request} req 
 * @param {express.Response} res 
 */
function test(req, res) {
  req.
}

https://github.com/Microsoft/TypeScript/issues/14377 also tracks allowing you to specify module imports in jsdocs directly.

Upvotes: 1

Related Questions