Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

angular - AngularJS 2.0 compile to ES6

I can get the AngularJS 2.0 5 Minute Quickstart working in my IntelliJ IDEA 14.1.4 following this Stackoverflow Answer regarding AngularJS 2.0 TypeScript Intellij idea (or webstorm) - ES6 import syntax.

However, this appears to be targeting compilation of TypeScript to EcmaScript 5.

I wanted to see if I could get AngularJS 2.0 Typescript to compile to EcmaScript 6.

Issue 1: When I change the TypeScript compiler to target ES6 ...

IntelliJ TypeScript compiler

I start getting a TypeScript compiler error:

Error: TS1204: Cannot compile modules into 'commonjs', 'amd', 'system', or 'umd' 
when targeting 'ES6' or higher.

I can get around it by removing the --module "amd" TypeScript compiler option.

This does beg the question: without specifying amd, what sort of module format is ES6 using?

Issue 2:

After modifying the TypeScript compiler options so they appear as follows:

IntelliJ TypeScript compiler

I start getting errors regarding:

Error TS2300: Duplicate identifier 'Promise'

TypeScript Error TS2300: Duplicate identifier 'Promise'

Has anyone seen this before? I suspect it has something to do with the AngularJS 2.0 Quickstart specifying ES-6 Promise and it being installed globally, but have not been able to figure out how to resolve it.

Thank you very much in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

without specifying amd, what sort of module format is ES6 using?

With target es6 only system is supposed to be allowed. The fact that amd worked is actually a bug.

Duplicate identifier 'Promise'

With target es6 lib.d.ts changes into lib.es6.d.ts (this file) which has an included definition for Promise.

Recommended fix:

More about lib.d.ts http://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...