title: How do you type an async express middleware function in Typescript?
body: <p>How do you define a return value for an express middleware that uses async/await?  I've tried a few different things but haven't had much luck.  </p>
  
  <p>I'm also trying to overload the Request object to allow req.user to be defined when we decode the JWT payload.</p>
  
  <pre><code>import { NextFunction, Request, RequestHandler, Response } from 'express'
  
  const authenticate: RequestHandler = async (req: IUserRequest, res: Response, next: NextFunction): Promise&lt;void&gt; =&gt; {
    if (! req.headers.authorization) { return next(new ValidationError()) }
    const payload: IUserData = await decodeJwt(req.headers.authorization)
    req.user = payload
    return next()
  }
  
  export interface IUserRequest extends Request {
    user: IUserData
  }
  
  /* errors 
  (req: IUserRequest, res: Response, next: NextFunction) =&gt; Promise&lt;void&gt;' is not assignable to type 'RequestHandler'.
    Types of parameters 'req' and 'req' are incompatible.
      Type 'Request' is not assignable to type 'IUserRequest'.
        Property 'user' is missing in type 'Request'.
  */
  </code></pre>