title: Typescript - How to create nested interface for json object
body: <p>I am trying to create nested json object for which I have created Interface.I am getting error as <code>Type of property serservicesAndHeads are incompatible</code> and says <code>Property is missing</code>. My Interface is as follows:</p>
  
  <pre><code>  interface  Head {
      HeadNumber?: string;
      HeadDescription?: string;
    };
  
    interface  ServicesAndHead {
      majorService?: string;
      subMajorService?: string;
      servicesAndHeads:Head[];
    }
  
    export interface MyTableItem {
     demandNo?: string;
     demandName?: string;
     servicesAndHeads?:ServicesAndHead;
     //servicesAndHeads?:ServicesAndHead[];
    }
  </code></pre>
  
  <p>Where my json looks like this:</p>
  
  <pre><code>  const dataItem: MyTableItem =
    {
      demandNo: 'Demand Number 2',
      demandName: 'Animal Husbandary, Livestock, Fisheries and Veterinary Services',
      servicesAndHeads: [
      {
        majorService: 'C-Economic Service',
        subMajorService: '(a) Agriculture and Allied Activities',
        majorHead: [
         { majorHeadNumber: '3098', majorHeadDescription: 'Animal Husbandry' },
         { majorHeadNumber: '3999', majorHeadDescription: 'Diary Development' },
         { majorHeadNumber: '4902', majorHeadDescription: 'Fisheries' }
        ]
      },
      {
        majorService: 'C- Capital Account of Economic Services',
        subMajorService: '(a) Capital Account of Agriculture and Allied Activities',
        majorHead: [
          { majorHeadNumber: '0012', majorHeadDescription: 'Capital Outlay on Animal ' },
          { majorHeadNumber: '3245', majorHeadDescription: 'Capital Outlay on Fisheries' }
        ]
       }
     ]
    }
  </code></pre>
  
  <p>I have tried this as well for nesting of serviceAndHead  </p>
  
  <pre><code>  servicesAndHeads?: {
        [key: string]:ServicesAndHead,
        majorHeads?: {
          [key: string]:MajorHead
        };
    };
  </code></pre>
  
  <p>How would I rectify my code to accept the said json.</p>