【问题标题】:Angular2 app not working in IE with ES6, and compile errors with ES5Angular2 应用程序无法在 IE 中使用 ES6,并使用 ES5 编译错误
【发布时间】:2016-10-14 15:16:40
【问题描述】:

我有一个使用 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"
  ]
}

【问题讨论】:

    标签: angular ecmascript-5 typescript2.0


    【解决方案1】:

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

    第二个,可以贴一下行号吗?

    【讨论】:

    • 我一直在使用 es6。当我更改为 es5 时,出现了很多错误。这只是几个。我添加了这样的 TS 定义: /// 但仍然得到错误。
    • 使用那些 TypeDefinition 你仍然得到 Promise 的错误?也有这个:/// 。导入此 TS 定义后,至少 Promise 错误应该消失。
    • 我看到我也以 es5 为目标,但如果我尝试使用 Promise,它会从 node_modules/typescript/lib/lib.es2015.promise.d.ts 导入
    • 当我使用 /// i得到似乎与该库相关的不同编译错误:错误 TS2318:找不到全局类型“数组”。错误 TS2318:找不到全局类型“布尔”。错误 TS2318:找不到全局类型“函数”。
    • 我使用 declare var Promise “修复”了承诺问题 - 感觉很脏。我遇到了一种错误:类型“租户 []”上不存在属性“查找”。我在几个数组上得到了这个。
    猜你喜欢
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    相关资源
    最近更新 更多