In your instance, there is no point re-declaring the class member...
export class myapp{
myarr = ['me', 'myself', 'i'];
title = this.myarr[0];
detail = this.title ;
}
Why is TypeScript doing this?
TypeScript is helping you to spot that you may have accidentally declared a second member with the same name by stopping you from doing what you are attempting.
You will also note that you don't need to use the this
prefix for members in a class. The generated JavaScript will have them...
var myapp = (function () {
function myapp() {
this.myarr = ['me', 'myself', 'i'];
this.title = this.myarr[0];
this.detail = this.title;
}
return myapp;
}());
You can prefix the members with an access modifier. They are private by default.
export class myapp{
private myarr = ['me', 'myself', 'i'];
protected title = this.myarr[0];
public detail = this.title ;
}
Access modifiers are enforced at compile time only.