mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
[koa-router] Change type of returned middleware to match type that Koa expects
Koa router has two types of middleware: the middleware it accepts for routes like `router.get(path, middleware)` and the middleware it creates, like `router.routes()`, that is passed to `koa.use(...)`. The former takes context objects with a `params` field while the latter doesn't. These are two different types of middleware and this commit changes the TypeScript declaration to reflect those two different types. This fixes a type error where `koa.use(router.routes())` fails to type check because the `Context` that Koa will pass in doesn't satisfy `IRouterContext` that `router.routes()` wanted.
This commit is contained in:
Vendored
+3
-3
@@ -225,19 +225,19 @@ declare class Router {
|
||||
/**
|
||||
* Returns router middleware which dispatches a route matching the request.
|
||||
*/
|
||||
routes(): Router.IMiddleware;
|
||||
routes(): Koa.Middleware;
|
||||
|
||||
/**
|
||||
* Returns router middleware which dispatches a route matching the request.
|
||||
*/
|
||||
middleware(): Router.IMiddleware;
|
||||
middleware(): Koa.Middleware;
|
||||
|
||||
/**
|
||||
* Returns separate middleware for responding to `OPTIONS` requests with
|
||||
* an `Allow` header containing the allowed methods, as well as responding
|
||||
* with `405 Method Not Allowed` and `501 Not Implemented` as appropriate.
|
||||
*/
|
||||
allowedMethods(options?: Router.IRouterAllowedMethodsOptions): Router.IMiddleware;
|
||||
allowedMethods(options?: Router.IRouterAllowedMethodsOptions): Koa.Middleware;
|
||||
|
||||
/**
|
||||
* Redirect `source` to `destination` URL with optional 30x status `code`.
|
||||
|
||||
Reference in New Issue
Block a user