Underscore Underscore - 1 month ago 9
TypeScript Question

Importing node and express with typings in TypeScript

I am trying to set up a TypeScript express/node application in Visual Studio Code following the Microsoft guide but changing it to use TypeScript however when it comes to installing the type definitions using

typings
I seem to have to install more packages than the guide.

I'm running the following pair of commands:

typings install node --ambient --save
typings install express --ambient --save


However attempting to build with just those packages gives the following type of error:

error TS2307: Cannot find module 'serve-static'.


For the following typings:


  • mime

  • express-serve-static-core

  • serve-static



I can resolve this by installing the required typings but it seems like something typings should do by itself.

I wanted to check if I was missing a fundamental step to automatically pull in dependencies or whether the guide was outdated?

In case it's relevant, my tsconfig.json:

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"outDir": "bin",
"sourceRoot": "src"
},
"exclude": [
"node_modules",
"typings/browser.d.ts",
"typings/browser"
]
}


My tsc is version 1.8.7 and I have typescript installed globally.

Answer

The tutorial I linked has now been updated to include the following commands:

typings install node --ambient
typings install express serve-static express-serve-static-core --ambient

See @cdbajorin 's comment for information about why dependencies are not automatically downloaded.

Comments