title: Errors when mapping over an array of objects and introducing a new property - Typescript
body: <p>I have an array of objects and I would like to loop over them and introduce a new property called 'colors' based on the value of 'y'.</p>
  <p>The function works fine as expected, however I get some compile errors.</p>
  <p>This is my code:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>interface IChartData {
    name: string;
    y ? : number;
    isSum ? : boolean;
  }
  
  interface IColorChartByValue extends IChartData {
    color: string;
  }
  
  const colorChartByValue = (
    data: IChartData[]
  ): IColorChartByValue[] =&gt; {
    return data.map((item: IChartData, index: number, array: IChartData[]) =&gt; {
      if (index === 0 || index === array.length - 1) {
        item.color = '#137cbd'
      } else if (item.y &gt;= 0) {
        item.color = '#0F9960'
      } else if (item.y &lt; 0) {
        item.color = '#D9822B'
      }
      return item;
    });
  };
  
  
  const chartData: IChartData[] = [{
      name: 'Base Case',
      y: 100000,
    },
    {
      name: 'Waterfall 1',
      y: 11500,
    },
    {
      name: 'Waterfall 2',
      y: 5677,
    },
    {
      name: 'Waterfall 3',
      y: -3001,
    },
    {
      name: 'Waterfall 4',
      y: 6500,
    },
    {
      name: 'Upside',
      isSum: true,
    },
  ]
  
  console.log(colorChartByValue(chartData))</code></pre>
  </div>
  </div>
  </p>
  <p>This is the playground link: <a href="https://www.typescriptlang.org/play?#code/AQiWDsBcFMCcDMCGBjawCSBhAFo2kARRSRYAbwCgRxEBbaALmAGdJYIBzAbiuAE8A-E3ABXWgCM4PMMwDKYocHEB7ZQBtoicDwC+FChBgIUaLOuWwceSACE+ANURqRaaAA8Y4ACbMMV-EQk5LzI5rBMrOzg3BR6IcrgrMChahb+tg5OLsAAvMAAFLwgXsSITFi4AaUA2gC6vACU5Zhh6XaOztB1uQB8wSAgsNCQIrDgwCUkAHS0iAAO+fmgMLTNlYSlADTAEF7uwmKSsNt4sIh8DBXWgYjdDb39A6DwBbvuuTl5AAzAAD6-O2870+eVO5ymGmikGwwAAtMAAIz3SgDJ4rKYpCy5YAAcgAxAiAMwAdmQ4i8OKKwD0qOer3RfGAPW+wAAZKzAXs3MAAISfYA-dmc9580GwM58CHQKEw+FIx609GY2DY-FfABiAE5NQA2L6U1E0p4vJYM4AAHgFbI5b25oqtQttvP5YMlkI40LhiORVLASrCqrxBE1AA4AExhmwGgZG1FDEZjHYraQxhopnQ8fQgUKJSDJdY3NbXGq1bHVKko1HAGj0Jg4myIZhoTCN6A4za+-hMBFfXu9juGgcDSuomuMXEAdWIcCQajUiPbnYuiIRAFZ+1SdEOQCOBmO61OjLP52HF1Wu8BVzricTt9S77vqHRxzjDzOnPPCWeq8vYYTewid5bhWnb7pO07GHOwAACzfqiy46uuXxAQ+oHPnWACqczMKAexwU8chiEwbAuChvD1PEiTqNAELKBw+TKm0mSdAxBalA0DRAA" rel="nofollow noreferrer">Link</a></p>
  <p>Any help is appreciated. Thanks.</p>