From 2b4c81593a3bd84e191fa800fc93955a917199b2 Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Sun, 18 Nov 2018 18:40:30 +0100 Subject: [PATCH] [koa-router] Replace object type by an interface type for router matching (#30587) * feat(koa-router): replace Object by IRoutesMatch; rename param * docs(koa-router): add contributor --- types/koa-router/index.d.ts | 9 ++++++++- types/koa-router/koa-router-tests.ts | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/types/koa-router/index.d.ts b/types/koa-router/index.d.ts index b63bb3f38e..8d8f35df6b 100644 --- a/types/koa-router/index.d.ts +++ b/types/koa-router/index.d.ts @@ -5,6 +5,7 @@ // JounQin // Romain Faust // Guillaume Mayer +// Andrea Gueugnaut // Definitions: https://github.com/hellopao/DefinitelyTyped // TypeScript Version: 2.3 @@ -92,6 +93,12 @@ declare namespace Router { query: object | string; } + export interface IRoutesMatch { + path: Layer[]; + pathAndMethod: Layer[]; + route: boolean; + } + export class ParamName { asterisk: boolean; delimiter: string; @@ -298,7 +305,7 @@ declare class Router { /** * Match given `path` and return corresponding routes. */ - match(name: string, method: string): Object; + match(path: string, method: string): Router.IRoutesMatch; /** * Run middleware for named route parameters. Useful for auto-loading or validation. diff --git a/types/koa-router/koa-router-tests.ts b/types/koa-router/koa-router-tests.ts index b5a4083146..e1c90c636d 100644 --- a/types/koa-router/koa-router-tests.ts +++ b/types/koa-router/koa-router-tests.ts @@ -44,6 +44,8 @@ router.get('user', '/users/:id', function (ctx) { ctx.body = "sdsd"; }); +const match = router.match('/users/:id', 'GET'); + let layer: Router.Layer let layerOptions: Router.ILayerOptions