【发布时间】:2016-01-09 13:33:17
【问题描述】:
我想将我用 Typescript 编写的 Angular2 应用程序编译成 ES6 代码,计划最近使用 Babel 将其编译成 ES5。但我得到了错误:
node_modules/angular2/typings/es6-shim/es6-shim.d.ts(6,14): error TS2300: Duplicate identifier 'PropertyKey'.
<...>
node_modules/typescript/lib/lib.es6.d.ts(3841,14): error TS2300: Duplicate identifier 'PropertyKey'.
<...>
我已尝试将指令 noLib 添加到我的 tsconfig.json 来解决此问题,但其中一个角度文件 (zone.d.ts) 需要导入 es6-shim.d.ts 与
/// <reference path="es6-shim/es6-shim.d.ts" />
它与主要的 typescript ES6 库 (lib.es6.d.ts) 冲突。
我该如何解决这个问题?
【问题讨论】:
-
您确定要编译到 ES5 吗?当您尝试将 angular2 编译为 es6 时,通常会显示此错误,因为 TSC 将提供它自己的 es6 库。检查 tsconfig.json 中的目标。
-
@toskv 我正在尝试将项目编译为 ES6,因为我想使用只能通过 Babel 编译使用的
Symbol.iterator。 -
@GünterZöchbauer,所以,这是一个错误?我认为它可以通过一些设置魔法来解决,但如果它是一个错误,我似乎无法做到。感谢您的帮助。
-
这个问题不是因为编译时引用了2个es6-shim.d.ts文件吗?听起来和这个问题一样github.com/DefinitelyTyped/DefinitelyTyped/issues/5015
标签: javascript angular typescript