The first problem is that VS Code is not able to determine that the app really is of type Express . This is why your second version of route.js makes sense.
The problem with this is that object types are not supported in JSDoc, as VS Code interprets.
VS code internally uses the JavaScript JavaScript service, as shown here . The fact is that the JavaScript service itself is actually TypeScript (see the links to it on the same page).
This answers your question in the following ways:
First, the JSDoc annotations supported by VS Code are the same as those supported by TypeScript . And from the TypeScript documentation this is not supported:
function fn7(param1) {}
And so your second attempt did not work.
But this is supported:
var var12;
So, if you are very adventurous, you can add the most necessary properties in this way. I don’t think it was even worth the effort.
The ultimate alternative would be to actually use TypeScript. This does not have to be of great importance to your code and will give you the necessary type information.
So, I created route.ts , which looks like this:
import 'node'; import { Express } from 'Express'; module.exports = function(app: Express) {
This saves type and IntelliSense information and works like a charm. The trade-off is that you need one more build step (which you can transparently handle in your task runner or with tsc --watch ).
Then you get the IntelliSense that you need without being tied to ES6 (TypeScript config uses ES5 by default) and without being forced to use more TypeScript than you want. Everything else from your code can be plain JavaScript if you like it.
Recall that your three alternatives are:
- No IntelliSense.
- Enter annotations that explicitly list the required properties or functions.
- Use TypeScript annotations.
Change I must add that I also set TypeScript type imports for Node and Express. I'm not sure if they are clearly necessary, but you should probably install them if you want to go this route.
Use this:
npm install @types/node npm install @types/express