From 098ee2ffeb615c3387eda384750665d18a022099 Mon Sep 17 00:00:00 2001 From: Guillaume Mayer Date: Wed, 24 Oct 2018 03:33:15 -0300 Subject: [PATCH] remove 2 arg version, Object to any --- types/koa-router/index.d.ts | 22 ++++++++++------------ types/koa-router/koa-router-tests.ts | 18 +++++++++++------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/types/koa-router/index.d.ts b/types/koa-router/index.d.ts index 29e85a75de..93473626fa 100644 --- a/types/koa-router/index.d.ts +++ b/types/koa-router/index.d.ts @@ -263,26 +263,24 @@ declare class Router { /** * Generate URL for route. Takes either map of named `params` or series of * arguments (for regular expression routes) - */ - url(name: string, params: Object): string; - url(name: string, params: Object): Error; - - /** - * Generate URL for route with query part. * - * Takes either map of named `params` or series of - * arguments (for regular expression routes) + * router = new Router(); + * router.get('user', "/users/:id", ... * - * Query is generated from `options` argument: + * router.url('user', { id: 3 }); + * // => "/users/3" + * + * Query can be generated from third argument: * * router.url('user', { id: 3 }, { query: { limit: 1 } }); * // => "/users/3?limit=1" - * + * * router.url('user', { id: 3 }, { query: "limit=1" }); * // => "/users/3?limit=1" + * */ - url(name: string, params: Object, options?: Router.IUrlOptionsQuery): string; - url(name: string, params: Object, options?: Router.IUrlOptionsQuery): Error; + url(name: string, params: any, options?: Router.IUrlOptionsQuery): string; + url(name: string, params: any, options?: Router.IUrlOptionsQuery): Error; /** * Match given `path` and return corresponding routes. diff --git a/types/koa-router/koa-router-tests.ts b/types/koa-router/koa-router-tests.ts index d7b3807b2d..b5a4083146 100644 --- a/types/koa-router/koa-router-tests.ts +++ b/types/koa-router/koa-router-tests.ts @@ -14,16 +14,20 @@ router .get('/', function (ctx, next) { ctx.body = 'Hello World!'; }) - .get('/users/:id', function (ctx, next) { - ctx.body = ctx.router.url('user-accounts', { id: ctx.params.id }) + .get('user', '/users/:id', function (ctx, next) { + ctx.body = { + test1: ctx.router.url('user-accounts', { id: ctx.params.id }), + test2: ctx.router.url('user-accounts', ctx.params.id), + test3: ctx.router.url('user-accounts', [ctx.params.id]), + } }) .get('user-accounts', '/users/:id/accounts', function (ctx, next) { ctx.body = { - test1: ctx.router.url('users', { id: 3 }, { query: { limit: 1 } }), - test2: ctx.router.url('users', { id: 3 }, { query: "limit=1" }), - test3: ctx.router.url('users', 3, { query: { limit: 1 } }), - test4: ctx.router.url('users', [3], { query: "limit=1" }), - test5: ctx.router.url('users', ["3"], { query: { limit: "1" } }), + test1: ctx.router.url('user', { id: 3 }, { query: { limit: 1 } }), + test2: ctx.router.url('user', { id: 3 }, { query: "limit=1" }), + test3: ctx.router.url('user', 3, { query: { limit: 1 } }), + test4: ctx.router.url('user', [3], { query: "limit=1" }), + test5: ctx.router.url('user', ["3"], { query: { limit: "1" } }), } }) .post('/users', function (ctx, next) {