question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Signature Mismatch in `MiddlewareInterface`

See original GitHub issue

Consider the following code (note the Request/Response type hints):

export class MyMiddleware implements MiddlewareInterface {
    use(request: Request, response: Response, next?: Function): any {

Compiling throws the following error:

error TS2420: Class 'MyMiddleware' incorrectly implements interface 'MiddlewareInterface'.
  Types of property 'use' are incompatible.
    Type '(request: Request, response: Response, next?: Function) => any' is not assignable to type '{ (request: any, response: any, next?: (err?: any) => any): any; (context: any, next: (err?: any)...'.
      Types of parameters 'response' and 'next' are incompatible.
        Type '(err?: any) => Promise<any>' is not assignable to type 'Response'.
          Property 'status' is missing in type '(err?: any) => Promise<any>'.

This, however, works:

export class MyMiddleware implements MiddlewareInterface {
    use(request: any, response: any, next?: Function): any {

I tracked the issue to the second (Koa) signature in MiddlewareInterface (removing it fixes the above but, obviously, won’t make Koa happy). It looks like my code makes the TypeScript compiler think I’m trying to implement the second signature.

While I tried changing/adding signatures in MiddlewareInterface, I couldn’t get it to compile.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pleerockcommented, Apr 24, 2017

new middleware interface signatures are being added in #119

0reactions
github-actions[bot]commented, Dec 16, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot SigV4 signature mismatch errors with IAM ...
How can I troubleshoot signature mismatch errors when making SigV4 signed requests with IAM authentication to API Gateway?
Read more >
Immediately respond from Middleware
Hi there, Is there a way for a middleware to immediately return a response to the client without going through the routes?
Read more >
Slim Framework Is Giving A Confuing Uncaught TypeError
Your middleware is not implementing PSR-15. You shouldn't pass a response, but a request handler interface: namespace Psr\Http\Server; ...
Read more >
middleware.go - gorilla/mux - Sourcegraph
Use appends a MiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify requests and/or responses, and are executed in...
Read more >
commit
Handler +} + +// MiddlewareFunc also implements the middleware interface. ... ServeHTTP(w, r) + }) + }) + + // Test method mismatch...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found