Angular 2 apps can be written in ES5, ES6, or TypeScript

Jun 26, 2015 09:22 GMT  ·  By

Yesterday we reported on the current status of AngularJS 2.0 branch, as presented by the Angular team itself at the Angular U conference in San Francisco.

While yesterday, we focused on how the team aims to improve performance by splitting the rendering engine from the core, by adding server-side rendering support, and by integrating React Native and NativeScript for developing mobile applications, we still left out some other updates.

These have to do with Angular's core, which was created in such a way to allow developers to use any version of JavaScript they want, may it be ES5, ES6, or even Microsoft's TypeScript, its own superset of the JavaScript language.

"In Angular 2, we're gonna make it work great [...] if you decide to use today's JavaScript, ECMAScript 5, [...] if you're gonna go to use the next generation, in ECMAScript 6, [...] [and even if you go] all the way into types and decorators," said Brad Green, engineering director at Google in charge of the AngularJS project.

The origin of this design resides back in October 2014, when work on the new Angular 2.x branch started and the team had to pick between using plain ol' JavaScript as before, Dart, or developing their own, more advanced version of JavaScript.

They chose the last option and started work on their own JavaScript superset called AtScript.

AngularJS 2.0 is written in Microsoft's TypeScript

As it turned out, AtScript and Microsoft's TypeScript had more things in common than anyone expected, and in March 2015 at the ng-conf conference in Utah, the two teams united and decided to merge AtScript into TypeScript and use the last to build the new Angular 2 core.

Leveraging on their experience with the previous 1.x branch, the Angular team also knew it had to prepare for situations where Angular needed to be used with various tools and technologies written in different versions of JavaScript.

This is the reason why the team organized the core in such a way that applications can be written using different layers of the JavaScript ecosystem.

At the base of the core there's ECMAScript 5 support, which can then be easily expanded to ECMAScript 6 whenever needed, or replaced with TypeScript to benefit from all those features plus JS types, or expanded with even more features like annotations and decorators.

Misko Hevery presented a demo app during the Angular's team presentation, in which he showed developers how easy it is to switch from one language version to another in Angular 2. The video is available online, and Misko comes after 26:00.