摆脱打字配置并添加@types会在编译项目时产生一系列错误。显然,typescript编译器和VS IntelliSense可以看到@ types / core-js。
这是一个很多错误之一的例子
Severity Code Description Project File Line Suppression State
Error TS2304 Cannot find name 'Set'. TypeScript Virtual Projects C:\Projects\Cool\Project\node_modules\@angular\common\src\directives\ng_class.d.ts 46 Active
Severity Code Description Project File Line Suppression State
Error TS2304 Cannot find name 'Promise'. TypeScript Virtual Projects C:\Projects\Cool\Project\node_modules\@angular\common\src\pipes\async_pipe.d.ts 44 Active
设置和承诺由core-js定义
关注 package.json 配置
"name": "Cool",
"private": true,
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w"
},
"dependencies": {
"@angular/common": "~2.1.1",
"@angular/compiler": "~2.1.1",
"@angular/core": "~2.1.1",
"@angular/forms": "~2.1.1",
"@angular/http": "~2.1.1",
"@angular/platform-browser": "~2.1.1",
"@angular/platform-browser-dynamic": "~2.1.1",
"@angular/router": "~3.1.1",
"@angular/upgrade": "~2.1.1",
"@types/core-js": "^0.9.34",
"@types/mcustomscrollbar": "^2.8.30",
"angular-in-memory-web-api": "~0.1.13",
"animate.css": "3.5.2",
"bootstrap": "~3.3.5",
"core-js": "^2.4.1",
"es6-promise": "^4.0.3",
"es6-shim": "^0.35.1",
"font-awesome": "^4.6.3",
"jquery": "2.1.4",
"malihu-custom-scrollbar-plugin": "~3.1.5",
"material-design-iconic-font": "~2.2.0",
"moment": "^2.15.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"@types/node": "^6.0.45",
"typescript": "^2.0.6"
}
}
这是 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./Scripts/app",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"jsx": "react",
"typeRoots": [
"./node_modules/@types"
]
},
"exclude": [
],
"files": [
"./Scripts/src/main.ts"
],
"compileOnSave": true
}
帮助表示赞赏!!!
答案 0 :(得分:1)
事实证明我有tsc 1.8。通过安装tsc 2.0.x,所有编译错误都消失了。感谢。