title: How to use a class as a type for properties of another class in typescript?
body: <p>I am new to typescript. I have defined some classes. I have used them as a type for the property of another class. e.g:</p>
  
  <p><strong>fileone.ts</strong></p>
  
  <pre><code>export class A {
     propertyOne: string;
     propertyTwo: string;
  }
  </code></pre>
  
  <p>Now i have another class B in another file:</p>
  
  <p><strong>filetwo.ts</strong></p>
  
  <pre><code>import { A } from './fileone';
  export class B {
      myProperty: A;
      mySecondProperty: string;
  }
  </code></pre>
  
  <p>I have instantiated this class B in another file. 
  I have the following code:</p>
  
  <p><strong>myapp.ts</strong></p>
  
  <pre><code>import { B } from './filetwo';
  export class C {
      let myObj: B = new B();
      myObj.myProperty.propertyOne = 'hello';
      myObj.myProperty.propertyTwo = 'world'';
      console.log(myObj);
   }
  </code></pre>
  
  <p>Now when i try to set the property of A through B, it say the following error: </p>
  
  <p><code>Cannot set the property "propertyOne" of undefined</code></p>
  
  <p>Can we not do this like in java? And please explain why i cannot do what i am doing right now. And what is the correct approach for this. Please do not just give me solution to my problem but also an explanation.</p>