在 tsconfig.json 文件中设置为 es5 时,我无法编译 Angular 2 应用程序。如果我将其更改为 es6,所有编译器错误都会消失。
tsconfig:
"compilerOptions": {
"target": "es5",
"module": "system",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"moduleResolution": "node"
},
"files": [ ...
索引.html
<script src="~/node_modules/systemjs/dist/system.src.js"></script>
<script src="~/node_modules/es6-shim/es6-shim.min.js"></script>
<script src="~/node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="~/node_modules/moment/min/moment.min.js"></script>
<script>
System.config({
defaultJSExtensions: true,
baseURL: '/ECAV.Admin/node_modules',
packages: {
'app': { format: 'register', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' }
},
paths: {
'angular2/*': 'angular2/*',
'rxjs': 'rxjs/bundles/Rx.js',
'linqsharp': 'linqsharp/built/linqsharp',
'highcharts': 'highcharts',
'ng2-highcharts': 'ng2-highcharts/ng2-highcharts',
'lodash': 'lodash/lodash'
},
map: {
moment: 'moment/moment.js'
}
});
</script>
<script src="/Admin/node_modules/rxjs/bundles/Rx.js"></script>
<script src="/Admin/node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="/Admin/node_modules/lodash/lodash.js"></script>
示例错误(其中许多来自库类):
Build: Cannot find name 'Set'. Admin C:\dev\ecav\Admin\node_modules\angular2\src\common\directives\ng_class.d.ts 72
我的要求之一是在 IE11 中运行这个网站,所以我需要 es5。
任何帮助将不胜感激。
最佳答案
如果您要转译到 ES5,您可能需要设置 ///<reference path="node_modules/angular2/typings/browser.d.ts"/>
在你的主 typescript 文件中。
关于typescript - Angular 2 : Many errors compiling to ES5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36544153/