Und*_*ore 23 node.js typescript visual-studio-code
我试图在Microsoft指南之后在Visual Studio代码中设置TypeScript表达/节点应用程序,但是将其更改为使用TypeScript,但是在使用typings
我安装类型定义时,我似乎必须安装比指南更多的包.
我正在运行以下一对命令:
typings install node --ambient --save
typings install express --ambient --save
Run Code Online (Sandbox Code Playgroud)
但是,尝试使用这些包进行构建会产生以下类型的错误:
error TS2307: Cannot find module 'serve-static'.
Run Code Online (Sandbox Code Playgroud)
对于以下类型:
我可以通过安装所需的打字来解决这个问题,但似乎某些打字应该自己做.
我想检查一下我是否错过了自动引入依赖关系或者指南是否过时的基本步骤?
如果它是相关的,我的tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"outDir": "bin",
"sourceRoot": "src"
},
"exclude": [
"node_modules",
"typings/browser.d.ts",
"typings/browser"
]
}
Run Code Online (Sandbox Code Playgroud)
我的tsc是1.8.7版本,我在全球范围内安装了打字稿.
Jos*_*ion 31
自上个月发布TypeScript 2.0以来,安装打字的推荐工具是我们值得信赖的老朋友npm
而不是typings
或tsd
.
npm install @types/node --save
Run Code Online (Sandbox Code Playgroud)
使用npm,不再需要担心"全局"或"环境"安装.
您也不必担心<reference>
在源文件的顶部添加标记了; 只需将以下属性放入您的compilerOptions
in中tsconfig.json
,TypeScript编译器将自动找到您安装的npm类型:
"typeRoots": [ "node_modules/@types" ]
Run Code Online (Sandbox Code Playgroud)
这是一篇博文,更详细地解释了这一变化:https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/
我链接的教程现已更新,包括以下命令:
typings install node --ambient
typings install express serve-static express-serve-static-core --ambient
Run Code Online (Sandbox Code Playgroud)
有关为什么不自动下载依赖项的信息,请参阅@cdbajorin的注释.
归档时间: |
|
查看次数: |
15409 次 |
最近记录: |