title: Express Types for HTTP2
body: <p>I'd like to leverage the <code>http2</code> module in Node 10 in conjunction with Express and TypeScript (2.8.x).</p>
  
  <p>In can instantiate a server with something like:</p>
  
  <pre><code>import * as http2 from "http2";
  
  let server = http2.createServer({}, app).listen(8080);
  </code></pre>
  
  <p>The problem is that I'll get a type error for <code>app</code>.  The issue is that <code>http2.createServer</code> wants the second argument to be of type:</p>
  
  <pre><code>(request: http2.Http2ServerRequest, response: http2.Http2ServerResponse) =&gt; void
  </code></pre>
  
  <p>The problem is that according to <code>@types/express</code>, the type of <code>app</code> is (<a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/express-serve-static-core/index.d.ts#L844" rel="nofollow noreferrer">apparently</a>):</p>
  
  <pre><code>(req: Request | http.IncomingMessage, res: Response | http.ServerResponse): any
  </code></pre>
  
  <p>Now I can do an ugly cast like this:</p>
  
  <pre><code>import * as http2 from "http2";
  
  let server = http2.createServer({}, (app as any) as ((request: http2.Http2ServerRequest, response: http2.Http2ServerResponse) =&gt; void)).listen(8080);
  </code></pre>
  
  <p>But the issue is really later when I write my Express handlers, it seems that I would have to write them as:</p>
  
  <pre><code>(req: express.Request, res: express.Response) =&gt; {
    let req2 = (req as any) as http2.Http2ServerRequest;
    let res2 = (res as any) as http2.Http2ServerResponse;
    ...
  }
  </code></pre>
  
  <p>...in order to access all the <code>http2</code> functionality like push, no?</p>
  
  <p>So I'm having to do these casts on both ends.  Now, if there were a <code>@types/express-http2</code> that had all the Express typings but assuming an underlying core of <code>http2</code>, then none of this would be necessarily I would think.  But I couldn't find such a thing.</p>
  
  <p>I recognize this is a tricky typing problem because all the Express typings, as far as I can tell, are written with the assumption of <code>http</code> as the underlying service layer.  As I understand it, Express itself works fine with <code>http2</code>, but the issue is that the typings don't work cleanly.</p>
  
  <p>Am I missing something?</p>
  
  <p>P.S. - I would prefer Express, but if there is another Node based web framework that supports this combination of <code>http2</code> and TypeScript better, I could consider that as well.</p>