title: Typescript: converting type of array of classes to type of array of constructed classes
body: <p>there is a problem I've been struggling to solve for quite a time.</p>
  <p>I have a function, inside which I put two arguments:</p>
  <ul>
  <li><strong>classes</strong> - array of classes</li>
  <li><strong>mapper</strong> - function that takes an array of instances of these classes.</li>
  </ul>
  <p>Imagine the function like this:</p>
  <pre><code>const MapClasses = (classes, mapper) =&gt; {
    const instances = classes.map((item) =&gt; new item())
    return mapper(instances)
  }
  </code></pre>
  <p>How could I create a typescript declaration for this, to ensure that <strong>mapper</strong> will always accept an array of instances of <strong>classes</strong>.</p>
  <p>Example usage:</p>
  <pre><code>class Coords {
    x = 10
    y = 10
  }
  
  class Names {
    name = 'Some Name'
  }
  
  const mapper = ([coords, names]) =&gt; {
    return {
      x: coords.x,
      y: coords.y,
      myName: names.name,
    }
  }
  
  const mapped = MapClasses([Coords, Names], mapper)
  // { x: 10, y: 10, myName: 'Some Name'}
  </code></pre>
  <p>So I think it should be possible, to check if mapper is accessing the right values.</p>
  <p>I've got it working kinda this way:</p>
  <pre><code>type MapClasses = &lt;Classes, Mapped&gt;(
    classes: {
      [Property in keyof Classes]: new () =&gt; Classes[Property]
    },
    mapper: (instances: Classes) =&gt; Mapped,
  ) =&gt; Mapped
  </code></pre>
  <p>However in this case, errors show only on <strong>classes</strong> parameter, not the <strong>mapper</strong>.</p>
  <p>So is there any way to turn this behaviour around?<br />
  ....</p>
  <p>I will be thankful for any ideas.</p>
  <p>Have a nice day.</p>