title: Typescript class can't access attributes from object
body: <pre><code>export class Person {
      name: string;
      age: string;
      details: {
        occupation: string;
        height: string;
        gender: string;
      };
  }
  </code></pre>
  
  <p>This is an class I have defined in person.ts.</p>
  
  <p>In another file, I am trying to assign a values to all attributes in a new person object. I can access <code>name</code> and <code>age</code> but I cannot access any attributes in the details object, in the setData() method because the details object is undefined. The code looks like this.</p>
  
  <pre><code>import { Person} from '../Classes/person';
  
  export class AnotherClass{
  
    private person1: Person;
  
    constructor() {
      this.person1= new Person();
    }
  
    private setData(){
      this.person1.details.occupation = "doctor";
    }
  </code></pre>
  
  <p>Any help is appreciated.</p>