8

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"
      ]
    }
3
  • 1
    If you'd use real ES6 as a target (for whatever reasons), I would also avoid commonjs modules Commented Dec 15, 2015 at 12:07
  • 1
    Have you tried running it to see what happens? - In short, to answer your question: no, the typescript compiler will compile to either valid ES6 or valid ES5 so transpilation is no longer required. Commented Dec 15, 2015 at 12:09
  • @DennisJaamann I don't think all browsers support ES6. Should I use any transpiler like Babel to compile ES6 to ES5 so it can run on browsers? Commented Dec 15, 2015 at 13:04

3 Answers 3

22

Which target you pick is dependent on which browsers you support. Looking at the The ES6 Compatibility Table, we can make general guidelines about what to target. As long as the platform support is greater than or equal to TypeScript support, then we can estimate what we want to target:

target: ES3 - If you want to support:

  • IE8

target: ES5 - If you want to support:

  • IE11
  • (iOS) Safari 9
  • Opera Mini
  • Android Browser
  • Potentially Firefox ESR or Edge 14. They implement some/most of ES6, but there may be a few features missing. Check if you need said features or can polyfill/shim them.

target: ES6 (ES2015) - If you use these features and you want to support:

target: ES7 (ES2016) - If you use these features and you want to support:

target: ES2017 - If you use these features and you want to support:

target ES2018 - If you use these features and you want to support:

target ES2019 - If you use these features and you want to support:

target ES2020 - Which leaves us with the browsers than handle everything as of this post:

  • Firefox 74+
  • Chrome 80+ (include it's Edgium 80+ and Operium 67+ rebrands)
  • Safari 13.1

Hopefully this will give you an idea of what to target, but testing is essential to guarantee you support the platforms you want. There might be smaller features not in the compatibility table or something I missed, so be sure to test.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

3

The answer from Evan Plaice was good but it is now old (almost 18 months as of writing this). The compability table has changed a lot and it might be ok to target ES6 (ES2015) now. Check the table for the browsers you need to support.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.