I'm trying to get the Express @types working but without any success. I'm using Visual Studio Code and I'd really love to have the autocompletition working. So far I've seen that installing the @types it gives the autocompletition too.
Things that I've done:
Installed express with npm: npm i -g express
Installed express-generator with npm: npm i -g express-generator
Generated the project with express-generator
cd into the project
Ran npm i
Installed types with npm: npm i --save-dev @types/express
// Top of the file:
var express = require('express');
app.use(function (req, res: Express.Response, next) {
var err: any = new Error('Not Found');
//if I try to use res.end() it gets underlined in red
res.end('some text');
});
As you can see the Express.Response was suggested by vscode, so this kinda confuses me. How can you find the Express.Response type but not it's methods?
The 'funny' fact is that in plain js everything works. Am I missing something or doing something wrong?
Here's my tsconfig.json file if it can help:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"lib": [
"es2016",
"dom"
]
}
}
Any help will be really appreciated!
For some reason now import * as express from 'express' now gives me the correct completition and type checking. However trying this before didn't worked. That's odd, however closing it as solved.