Angular2应用程序无法在IE中使用ES6,并使用ES5编译错误

时间:2016-10-14 15:16:40

标签: angular ecmascript-5 typescript2.0

我有一个使用typescript(2.0.0)的angular2应用程序(2.0.0)。在我的tsconfig中,我使用以下行编译为es6:

"target": "es6",

它在Chrome和Edge中运行良好,但它在IE11中无效。

我将其更改为目标es5但后来我遇到了几个编译错误,例如:

ClientApp\app\services\tenant.service.ts(9,16): error TS2304: Cannot find name 'Promise'.
ClientApp\app\components\manage\users.component.ts(70,31): error TS2339: Property 'json' does not exist on type '{}'.

这确实产生了输出,并且在运行时似乎可以在IE11和其他浏览器中工作(但我还没有测试过所有内容)。我仍然不喜欢编译错误。

我包含了core-js。我认为这是解决这个问题的方法。

我应该定位5还是6?

es6应该在IE中运行吗?我缺少一个垫片吗?

如何使用es5并摆脱编译错误?

这是我的tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules"
  ]
}

1 个答案:

答案 0 :(得分:0)

对于第一个错误我认为你应该导入TypeScript定义https://github.com/borisyankov/DefinitelyTyped/blob/master/es6-promise/es6-promise.d.ts

对于第二个,你可以粘贴行代码吗?