title: Typescript Mapped Types or Arrays of Types
body: <p>I am trying to use Typescript mapped types for a simple query API. Let me provide a simplified example: </p>
  
  <pre><code>interface IRoot {
    user: IUser,
    trips: Array&lt;ITrip&gt;
  }
  
  interface IUser {
    name: string
  }
  
  interface ITrip {
    prop: string
  }
  </code></pre>
  
  <p>Now I can construct a query like this: </p>
  
  <pre><code>class Query&lt;T, K extends keyof T&gt; {
    constructor(
      private rootType: T, 
      private subQueries?: {[P in K]?: Query&lt;T[P], any&gt; }) { }
  }
  </code></pre>
  
  <p>This works fine to access user, but can't resolve the type of the array for trips: </p>
  
  <pre><code>new Query(({} as IRoot), {
    user: new Query(({} as IUser), ... /* This is a query on User and is accepted here */, 
    trips: new Query(({} as ITrip), ... /* This is a query on Trip and TS will complain, since T[P] is Array&lt;ITrip&gt; */
  })
  </code></pre>
  
  <p>Any ideas how I can extend <code>{[P in K]?: Query&lt;T[P], any&gt; }</code> to accept <code>T[P]</code> or if <code>T[P]</code> is an Array, the type of the array? </p>