Switch compilerOptions to es6 in tsconfig.json causes error

I am trying to use async and await in my project but when I try to compile it with ionic serve , it gives me the following error:

Error TS1311: Async functions are only available when targeting ECMAScript 6 and higher.

Thus, I changed "target": "es5", to "target": "es6", in tsconfig.json and tried to compile again.

This time, I expect it should work seamlessly but I got the following error:

TypeScript error: /node_modules/typescript/lib/lib.es6.d.ts(17,14): Error TS2300: Duplicate identifier 'PropertyKey'.
TypeScript error: /node_modules/typescript/lib/lib.es6.d.ts(237,5): Error TS2300: Duplicate identifier 'EPSILON'.
TypeScript error: /node_modules/typescript/lib/lib.es6.d.ts(272,5): Error TS2300: Duplicate identifier 'MAX_SAFE_INTEGER'.
TypeScript error: /node_modules/typescript/lib/lib.es6.d.ts(279,5): Error TS2300: Duplicate identifier 'MIN_SAFE_INTEGER'.
TypeScript error: typings/globals/es6-shim/index.d.ts(3,14): Error TS2300: Duplicate identifier 'PropertyKey'.
TypeScript error: typings/globals/es6-shim/index.d.ts(6,5): Error TS2300: Duplicate identifier 'done'.
TypeScript error: typings/globals/es6-shim/index.d.ts(7,5): Error TS2300: Duplicate identifier 'value'.
TypeScript error: typings/globals/es6-shim/index.d.ts(245,5): Error TS2300: Duplicate identifier 'EPSILON'.

(The above error messages are part of the entire error and the rest are the same as above)

This is weird. But generally, it seems like it includes more than one typescript type information file and both of them define same part of content.

So here is what I tried to after I gained this error, I looked at tsconfig.json, it is as following:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "filesGlob": [
    "**/*.ts",
    "!node_modules/**/*"
  ],
  "exclude": [
    "node_modules",
    "typings/global",
    "typings/global.d.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

( First, I would like to point out something strange in this tsconfig.json file. It seems like ionic team never updates this file? I didn’t find filesGlob definition and typings/global and typings/global.d.ts don’t even exist in my project… ) As you can see from the error message above, one of the typescript type information files actually comes from typings/globals(notice the s). I thought this might be the reason of the error since this exclude never worked and it is stilling including the typescript type information files. Thus, I changed those 2 lines to typings/globals and typings/index.d.ts (there is no global.d.ts file but there is index.d.ts file under typings folder) and compiled again.

Unfortunately, I failed again… ionic serve still gives me the same errors.

I am getting a bit frustrated but this time what I did is to directly modify this file typings/globals/es6-shim/index.d.ts which conflicts(see the above error message) and delete those duplicate part of code.

It worked…

However, I don’t think this is the right solution… I tried to google a lot but didn’t find the solution other than directly modify xxx.d.ts files.

Anyone could help? I just want to get this compilerOptions targeting to es6 work… Thanks!

The following is the info from ionic info

Your system information:

Cordova CLI: 6.3.1
Ionic CLI Version: 2.0.0-beta.37
Ionic App Lib Version: 2.0.0-beta.20
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Mac OS X Yosemite
Node Version: v6.4.0
Xcode version: Xcode 7.2.1 Build version 7C1002

@sharmuu I guess that if you target ES6 you should remove the es6-shim completely.

BUT you should take in mind that if you target ES6 your app most probably won’t work on most mobile OSes - you could check the support of ES6 among mobile browsers in this compatibility table.

Therefore I would recommend you to wait for TypeScript 2.1 which should add support for async / await also when targeting ES5.