title: How do I fix the error? Typescript: Type 'ErrorRequestHandler' is not assignable to type 'IMiddleware'
body: <p>In the following code, I got an error with type reassignment:</p>
  
  <pre class="lang-js prettyprint-override"><code>export default class AbstractController extends Middleware {
  
      get middleware(): Express.RequestHandler | Express.ErrorRequestHandler { // (6,22)
          //...
      }
  
  }
  </code></pre>
  
  <p>Error text:</p>
  
  <pre><code>src/controller/AbstractController.ts(6,22): error TS2415: Class 'AbstractController' incorrectly extends base class 'Middleware'.
    Types of property 'middleware' are incompatible.
      Type 'ErrorRequestHandler | RequestHandler' is not assignable to type 'IMiddleware'.
        Type 'ErrorRequestHandler' is not assignable to type 'IMiddleware'.
  </code></pre>
  
  <p>Declare RequestHandler and ErrorRequestHandler interfaces:</p>
  
  <pre class="lang-js prettyprint-override"><code>interface RequestHandler {
      (req: Request, res: Response, next: NextFunction): any;
  }
  
  interface ErrorRequestHandler {
      (err: any, req: Request, res: Response, next: NextFunction): any;
  }
  </code></pre>
  
  <p>Declare Middleware class:</p>
  
  <pre class="lang-js prettyprint-override"><code>export interface IMiddleware {
      (req: http.IncomingMessage, res: http.ServerResponse): void;
  }
  
  export default class Middleware {
  
      get middleware(): IMiddleware {
          throw new Error('Не определен middleware.');
      }
  
  }
  </code></pre>
  
  <p>I need to understand not how to fix it, but what is the cause of the error.</p>