title: Operator '+' cannot be applied to types 'number' and 'T[K]'
body: <p>I have this code block:</p>
  
  <pre><code>function sumOnValue&lt;T, K extends keyof T&gt;(collection: Array&lt;T&gt;, key: K): number {
    let result = 0;
    for (const o of collection) {
      const sample = o[key];
      if (typeof o[key] === 'number') {
        result = result + sample; // [ts] Operator '+' cannot be applied to types 'number' and 'T[K]'.  red squigly line under sample.
      }
    }
    return result;
  }
  
  const sampleCharges: Array&lt;ICharge&gt; = [
    {
      AllowedAmount: 10,
    },
    {
      AllowedAmount: 15,
    },
    {
      AllowedAmount: 9,
    },
  ];
  
  const resultedSum = sumOnValue(sampleCharges, 'AllowedAmount');
  console.log(resultedSum);
  </code></pre>
  
  <p>As depicted in the above, I get the error from the compiler (vscode reports it as a problem) but when running the code it's fine and doesn't complain. What should I be doing here to suppress the error or to write this method 'safely via type checking'?</p>
  
  <p><strong>The objective in a nutshell is:</strong> Add up a given attribute within an array of <code>T</code> provided that the given attribute is a type within <code>T</code> and that the attribute is a number.</p>