ES6 as the typescript target compiler option for angularjs or angular2

為{幸葍}努か 提交于 2019-12-05 11:58:34

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.

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.

First examining differences in TypeScript versions in the compatibility table, we only find a few differences:

Now comparing TS's feature set to the platforms:

target: ES3 - if you want to support:

  • IE8 - does not support ES5

target: ES5 - if you want to support:

  • IE11 - does not support ES6
  • (iOS) Safari 9 - does not support ES6
  • Opera Mini - does not support ES6
  • Android Browser - does not support ES6
  • Node 4 - does not support ES6
  • 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 want to use these features and you want to support:

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

I'll leave ES2018/ESNext as an exercise for the reader, or I may updated this in the future. It'd be a fair statement to say some modern browsers or libraries don't support some of their features as they can be experimental.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!