title: How can we define object type interface in typescript?
body: <p>I want to define a interface with object and different types
   such as </p>
  
  <pre><code>export interface example {
     code: string;
     category : {
       name : string,
       reference: string,
       sequence : number
     };
  }
  </code></pre>
  
  <p>In definition, there is no problem but after calling like</p>
  
  <pre><code>ex = {} as example;
  ex.category.name ='electric; 
  </code></pre>
  
  <p>this does not work and below error occurs</p>
  
  <blockquote>
    <p>ERROR Error: Uncaught (in promise): TypeError: Cannot set property 'name' of undefined
    TypeError: Cannot set property 'name' of undefined</p>
  </blockquote>
  
  <p>There are some similar subjects but they are not exactly related. (<a href="https://stackoverflow.com/questions/37425407/how-to-define-object-in-type-script-interface">How to define object in type script interface</a>  or <a href="https://stackoverflow.com/questions/27339590/how-can-i-define-the-types-of-an-object-variable-in-typescript">How can I define the types of an object variable in Typescript?</a>)</p>
  
  <p>I appreciate your assistance finding the solution.</p>