AngularJS 2 and TypeScript... some work to do...

After reading a great "First impressions" post on AngularJS 2 (http://blog.mgechev.com/2015/04/06/angular2-first-impressions/) I headed over to the code repository of AngularJS 2 to see how they write their code now in my favorite front-end language: TypeScript. After looking at some of the code it is clear that the team has still some TypeScript to learn. A little example of something you find in most of the code: for example in the fileĀ https://github.com/angular/angular/blob/master/modules/angular2/src/render/api.ts:

export class EventBinding {
fullName: string; // name/target:name, e.g "click", "window:resize"
source: ASTWithSource;

constructor(fullName: string, source: ASTWithSource) {
this.fullName = fullName;
this.source = source;
}
}

But one of the features of TypeScript is parameter property declaration and is shorthand for declaring a property with the same name as the parameter and initializing it with the value of the parameter. This would reduce the above code to:

export class EventBinding {
constructor(private fullName: string, private source: ASTWithSource) {
}
}

See chapter 8.3.1. of the TypeScript language specification.

And this is a really simple example. The code is full of this kind of initialization code.

1 Comment

Comments have been disabled for this content.