Importing node and express with typings in TypeScript

后端 未结 3 1949
广开言路
广开言路 2021-02-01 05:23

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 instal

相关标签:
3条回答
  • 2021-02-01 05:37

    to save everyone a headache, the magic command to get the typings for node is now:

    typings install node --source env --global --save

    0 讨论(0)
  • 2021-02-01 05:38

    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.

    0 讨论(0)
  • 2021-02-01 05:51

    As of the release of TypeScript 2.0 last month, the recommended tool for installing typings is our trusty old friend npm instead of typings or tsd.

    npm install @types/node --save
    

    With npm, there's no need to worry about "global" or "ambient" installations anymore.

    You also don't need to worry about adding <reference> tags to the top of your source files anymore; just drop the following property into your compilerOptions in tsconfig.json, and the TypeScript compiler will automatically find the npm typings you've installed:

    "typeRoots": [ "node_modules/@types" ]
    

    Here's a blog post that explains the change in some more detail: https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/

    0 讨论(0)
提交回复
热议问题