CBa*_*arr 5 visual-studio typescript typescript-typings typescript2.0 typescript-types
关于TS 2.x的一切@types看起来都很棒,但我不能为我的生活弄清楚如何让它正常工作!
14.0.25431.01 Update 32.1.4for Visual Studio 2015,我从这里得到了<TypeScriptToolsVersion>2.1</TypeScriptToolsVersion>这是我packages.json文件中的相关部分
"dependencies": {
"angular": "^1.5.9",
"angular-messages": "^1.5.9",
"angular-ui-bootstrap": "^2.3.0",
"angular-ui-router": "^0.3.2",
"moment": "^2.17.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"@types/angular": "^1.5.21",
"@types/angular-ui-bootstrap": "^0.13.36",
"@types/angular-ui-router": "^1.1.35",
"@types/jquery": "^2.0.34",
"@types/node": "^0.0.3",
"@types/signalr": "^2.2.32",
"@types/underscore": "^1.7.36"
}
Run Code Online (Sandbox Code Playgroud)
这是我的完整tsconfig.json档案
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true,
"target": "ES5"
},
"typeAcquisition": {
"enable": true
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过变化typeRoots和types指定(一个,另一个,两者都没有)compilerOptions,但没有运气!
"typeRoots": [
"./node_modules/@types"
],
"types": [
"angular",
"angular-ui-bootstrap",
"angular-ui-router",
"jquery",
"moment",
"signalr",
"underscore"
]
Run Code Online (Sandbox Code Playgroud)
我已经清理了构建版本,重新启动了Visual Studio等,但无论我做什么,我都会遇到构建错误
some-file.ts(8,22): error TS2304: Build:Cannot find name 'angular'.
some-file.ts(12,41): error TS2694: Build:Namespace 'angular' has no exported member 'IScope'.
some-file.ts(12,67): error TS2694: Build:Namespace 'angular' has no exported member 'IRootElementService'.
another-file.ts(26,22): error TS2503: Build:Cannot find namespace 'moment'.
another-file.ts(47,37): error TS2304: Build:Cannot find name 'moment'.
Run Code Online (Sandbox Code Playgroud)
所有typedef都存在于磁盘上node_modules/@types或与相关包本身存在.我不知道为什么Visual Studio/TypeScript找不到这些文件!我觉得有些东西还没有准备好发布,或者我错过了一些非常简单的东西.请有人在这里指出我正确的方向
小智 0
如果您还没有解决这个问题,请尝试从卸载/安装程序中卸载打字稿工具(您可能像我一样有多个版本)并通过您已有的安装包重新安装打字稿工具@ v2.1.4。在 Visual Studio 中仔细检查,这就是您正在使用的版本(它应该在帮助菜单中的“关于 microsoft Visual Studio”中包含详细信息)
这是我的 tsconfig,以防有帮助:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"typeRoots": [
"node_modules/@types"
]
},
"typeAcquisition": {
"enable": true
},
"exclude": [
"jspm_packages"
]
}
Run Code Online (Sandbox Code Playgroud)
这适用于导出模块的任何类型,但当它们不是模块(即只是接口等)时导入单个类型时我仍然遇到问题...
一般来说,我不必对import * from x库执行任何语句,并且能够仅使用直接导出的模块的名称。
| 归档时间: |
|
| 查看次数: |
468 次 |
| 最近记录: |