[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:
James Ide
2018-06-20 18:12:57 -07:00
parent 3e3487aa2c
commit 39d7e18f2a
+3 -3
View File
@@ -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`.