Signature Mismatch in `MiddlewareInterface`
See original GitHub issueConsider 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:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

new middleware interface signatures are being added in #119
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.