title: Passing a generic type to a function in typescript
body: <p>Consider example:</p>
  <pre><code>interface A {
     foo: string;
  }
  
  interface B {
     foo: string;
  }
  
  function a&lt;T&gt;() {
     function b(arg: T) {
        return arg.foo;
              ^^^^^^ Property 'foo' does not exist on type 'T'.
     }
  
     return b;
  }
  
  a&lt;A&gt;();
  a&lt;B&gt;();
  </code></pre>
  <p>How to make it work so I dont have to hardcore the type like:</p>
  <pre><code>function b(arg: A | B)
  </code></pre>
  <p>So I will be able to pass the type as a generic so if there's like 5 or even more different types I will not have to do it like <code>A | B | C | D | E...</code> but just as a generic?</p>