From 39d7e18f2a1ff78d38719ac007532daf4a47e368 Mon Sep 17 00:00:00 2001 From: James Ide Date: Wed, 6 Jun 2018 14:32:28 -0700 Subject: [PATCH] [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. --- types/koa-router/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/koa-router/index.d.ts b/types/koa-router/index.d.ts index 1ade4b135b..feda38f24b 100644 --- a/types/koa-router/index.d.ts +++ b/types/koa-router/index.d.ts @@ -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`.