title: TypeScript getter setter convention
body: <p>What is the convention (standard) in TypeScript for class attributes?</p>
  
  <p>In the angular 2 demo (The Heroes Tour from angular.io) all attributes are set to public :</p>
  
  <pre><code>export class Hero {
     id: number;
     name: string;
  }
  </code></pre>
  
  <p>So they can be instanciated both ways :</p>
  
  <pre><code>var hero: Hero = new Hero();
  hero.id = 0;
  hero.name = "hero";
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var hero2: Hero = {id : 0, name: "hero"};
  </code></pre>
  
  <p>Is there a Java style convention (like this) :</p>
  
  <pre><code>export class Hero {
     private id: number;
     private name: string;
  
     setId(id: number): Hero {
        this.id = id;
        return this;
     }
  
     setName(name: string): Hero {
        this.name = name;
        return this;
     }
  
     getId(): number {
        return this.id;
     }
  
     getName(): string {
        return this.name;
     }
  }
  </code></pre>
  
  <p>Declaration (exemple) :</p>
  
  <pre><code>var hero: Hero = new Hero();
  hero.setId(0).setName('hero');
  
  var hero2: Hero = new Hero().setId(0).setName('hero');
  </code></pre>