title: Constructor array of objects - Typescript
body: <p>I am using <code>typescript</code> to code in Angular2. I have this object:</p>
  
  <pre><code>export class Car{
      name: String;
      door: {
          position: String;
          id: Number;
      };
  }
  </code></pre>
  
  <p>I have initialized the object following this steps:</p>
  
  <pre><code>constructor() {
      this.door= new Door();
  }
  export class Door{
      position: String;
      ID: Number
  }
  </code></pre>
  
  <p>and it perfectly works. My problem begins when I try to initialize an array of objects</p>
  
  <pre><code>export class Car{
      name: String;
      door: {
          position: String;
          id: Number;
      };
      color: {
         one: String;
         two: String;
  
      }[]
  }
  </code></pre>
  
  <p>and I try to do the same
           <strong>Edited</strong></p>
  
  <pre><code>constructor() {
      for (var i = 0; i &lt; 10; i++) {
          this.color.push(new Color);
      }
          this.door= new Door();
      }
  
  
  export class Color{
      one: String;
      two: String;
  }
  </code></pre>
  
  <p>The error is the following:</p>
  
  <blockquote>
    <p>ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'push' of undefined
    TypeError: Cannot read property 'push' of undefined</p>
  </blockquote>