typescript - Angular 2 : Many errors compiling to ES5

标签 typescript angular

在 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 文件中。

来自:https://stackoverflow.com/a/35737470/3279156

关于typescript - Angular 2 : Many errors compiling to ES5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36544153/

相关文章:

angular - "Ionic dev app"和 "real mobile phone"上的空白屏幕

Angular Testing 模拟订阅属性

typescript - 如何使用 `...args` 将多个参数传递给基类?

http - 在 Angular2 HTTP POST 中设置 JSON 请求 header

node.js - Istanbul 尔/纽约仅获取部分文件

html - 我需要对 Angular 表单进行验证

typescript - 如何使用类验证器向nestjs中的验证器约束接口(interface)注入(inject)服务?

angular - 将 Angular 项目从 StackBlitz 导出到本地

angular - 类型 'bind' 上不存在属性 'void'

angular - 在 Angular 2 中抛出我自己的异常,Angular 用 viewWrappedDebugError 包装它