title: Can Typescript generic types be reused in multiple places?
body: <p>I have some code with a complex set of generics that I need to use in multiple places. Is there a way to reuse the same generics in multiple places? Or some other good way to simplify the type definitions in this example:</p>
  <pre class="lang-js prettyprint-override"><code>type OSD&lt;T, V&gt; = { [K in keyof T]?: V };
  
  export interface CommandProps&lt;
      ReqQ extends OSD&lt;ReqQ, string&gt; | undefined,
      ReqH extends OSD&lt;ReqH, string&gt; | undefined,
      ReqB extends OSD&lt;ReqB, unknown&gt; | undefined,
      ResH extends OSD&lt;ResH, string&gt; | undefined,
      ResB extends OSD&lt;ResB, unknown&gt; | undefined,
  &gt; {
      queryParametersSchema: ReqQ extends undefined ? undefined : Schema;
      requestHeadersSchema: ReqH extends undefined ? undefined : Schema;
      requestBodySchema: ReqB extends undefined ? undefined : Schema;
      responseHeadersSchema: ResH extends undefined ? undefined : Schema;
      responseBodySchema: ResB extends undefined ? undefined : Schema;
  }
  
  export default class Command&lt;
      ReqQ extends OSD&lt;ReqQ, string&gt; | undefined,
      ReqH extends OSD&lt;ReqH, string&gt; | undefined,
      ReqB extends OSD&lt;ReqB, unknown&gt; | undefined,
      ResH extends OSD&lt;ResH, string&gt; | undefined,
      ResB extends OSD&lt;ResB, unknown&gt; | undefined,
  &gt; {
      readonly queryParametersSchema: ReqQ extends undefined ? undefined : Schema;
      readonly requestHeadersSchema: ReqH extends undefined ? undefined : Schema;
      readonly requestBodySchema: ReqB extends undefined ? undefined : Schema;
      readonly responseHeadersSchema: ResH extends undefined ? undefined : Schema;
      readonly responseBodySchema: ResB extends undefined ? undefined : Schema;
  
      constructor(props: CommandProps&lt;ReqQ, ReqH, ReqB, ResH, ResB&gt;, queryParameters: ReqQ, requestHeaders: ReqH, requestBody: ReqB) {
          this.queryParametersSchema = props.queryParametersSchema;
          this.requestHeadersSchema = props.requestHeadersSchema;
          this.requestBodySchema = props.requestBodySchema;
          this.responseHeadersSchema = props.responseHeadersSchema;
          this.responseBodySchema = props.responseBodySchema;
      }
  
      // ... Other methods that use all of these fields
  }
  
  </code></pre>
  <p><a href="https://www.typescriptlang.org/play?#code/PTAEHkGUBFQXggBwC4EsD2A7AhgG0sgE6oDGy0paW2hAngFAiiQCmLoAFssogM4BcIXsmwkA1ugBuLQgDNc6AO4A6EugC2wAI4BXFsIyZewAGwmAnAFYTAFgDs54MlqJ9JYigC0s9IRItPAHMWTBlST2dXCPRPACMA7ExPdFiAKxYyekj2KGgAHgAVABpQADUAPnhQAG9QAG0AaVBUTFAxFlp0WVACgF0Afn4y0ABfAG56ehYAD0RfZGbMZBlZUXYAYQ11RIATAAVCdD48%20lAz0AAlFi0ARVAZ5cwd3ggYPKvbkuFiTEDKgB9QDonixZC0WDsiqdzh8ABL3aaPZ6vfJwr5EFp-UCA4E7UHgyHQs4fABCCKRL1y72uJJKwLEmCUmABQJBYNChPOl308IeIWRVKuvFh6J%20WJxbIJUK5QrJfKelLesrpmAZTJZuPxHKhlWqRNAiGwyA4Q2%20mImXPULGN6B2poxvwm%20t0Mloexo2Cty0IvEgJA4LG2Qw%20d3lyM17IhoH6rLxkZ2oCGfoD2wt50I1z0wlhLGweJ9ycD2GD115iP5LwjBOjsa1UaT-qLabOGZdwhJttohaD3K0cvLCtr8ZrVY5ieYjdT%20ozvDmRhYObzMl9k%20L3OF5IrQ%20rMdH9YnKewzdAM7nvBYHZ2XdXJd4-Yp27Hu8lY4bh4mI0mMzmhAWcewOi4AsJC4NgvAvJs6jbE8JwytcoYDgKSrwaKmIai%20ELSjCpaboOgqlqhvzoXGUr6qSuFIaiNIqmqijMtij6YWRPIUYqVHCoR4qMZy2F3qxKLUneNGMnRxF1oSurTrmOxYLgtAGkaJqgGajpSXmsnyV6HC2vaYpOlyGbqZgcmgC6dDuoQnrWsu3ZriG-F7gmz4ka%20B5NmpMnGfJrZZsgi75iuh4lloZYPo5I4YQmb7uQZ0kaSemb6Mgl7XkFvb3lu4XOeJ462cehmeSZp5YOe-k2Te66hZlkURS5%2055R58XFfOKW2beGWDll3G5au%20npnFXmmXo5k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