title: Returning a generic array using Array.map (TypeScript)
body: <p>I wrote a function that gets a string array and supposed to convert it to a T array:</p>
  
  <pre><code>interface Fooable {
      foo: string;
  }
  
  function simplifiedExample&lt;T extends Fooable&gt;(bars: string[]): T[] {
      return bars.map(bar =&gt; {
          return {
              foo: bar
          }
      })
  }
  </code></pre>
  
  <p>But the word "bars" in the first line of the function is marked by a red line, says:</p>
  
  <blockquote>
    <p>TS2322: Type '{foo:string;}[]' is not assignable to type 'T[]'. Type '{foo:string}' is not assignable to type 'T'.</p>
  </blockquote>
  
  <p>How can I make it work?</p>