Search code examples
angularjsecmascript-6ecmascript-5

ES6 as the typescript target compiler option for angularjs or angular2


The compiler option for my angularjs application is as below. Should I use any other package to transpile es6 to es5 again if I change the target to es6?

    {
      "compilerOptions": {
        "target": "es5", // Change this to es6
        "module": "commonjs",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "outDir": "./wwwroot/app/"
      },
      "exclude": [
        "node_modules",
        "wwwroot"
      ]
    }

Solution

  • Targeting ES5 is currently a baseline requirement

    *According to The ES6 Compatibility Table:

    • class isn't supported in

      • Chrome (latest)
      • Android (latest)

    Note: This is just for the latest. Many of the ES6 features that would provide a measurable benefit have only been implemented in the latest browser versions. Ie backward-compatibility is virtually nonexistent.

    There are likely other use cases that would be better described using ES6 that aren't fully supported by browser.

    In short, you should target ES5 for the foreseeable future until browsers have a chance to catch up.