title: How to add a extra property to array with typescript
body: <p>I want to add an extra property to an array, but I get trouble with declaring it.</p>
  
  <p>small part</p>
  
  <pre><code>const arr: string[] &amp; {key: number} = ['123'];//ts error  Property 'key' is missing
  arr.key = 10;
  </code></pre>
  
  <p>large part</p>
  
  <p>I need to group arr by index then sort it by value</p>
  
  <p>add an index to array property will be a convenience if using Object.values but not Object.entries.
  I know there are many approaches to do this, but I think it's much easier if I am using plain js</p>
  
  <pre><code>type Arr = {index: number, value: number};
  const arr:Arr[] = []
  arr.push({
      index: 10,
      value: 2
  })
  arr.push({
      index: 10,
      value: 1
  })
  arr.push({
      index: 10,
      value: 3
  });
  arr.push({
      index: 20,
      value: 100
  });
  arr.push({
      index: 20,
      value: 50
  });
  arr.reduce&lt;Record&lt;string, Arr[] &amp; {index: number}&gt;&gt;((prev, curr) =&gt; {
      if(!prev[curr.index]){
          prev[curr.index] = [];//ts error Property missing
          prev[curr.index].index = curr.index;
      }
      prev[curr.index].push(curr);
      prev[curr.index].sort((a,b) =&gt; a.value - b.value);//or some insertion sort algorithm.
      return prev;
  },{})
  </code></pre>