From 2b6f0e732d5b63352369dc658b751aa56d8f4b1c Mon Sep 17 00:00:00 2001 From: Jan Dolezel Date: Wed, 2 Jan 2019 15:03:21 +0100 Subject: [PATCH 1/2] Fixes after #31704 --- types/koa-router/index.d.ts | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/types/koa-router/index.d.ts b/types/koa-router/index.d.ts index 8d8f35df6b..81b0f697e6 100644 --- a/types/koa-router/index.d.ts +++ b/types/koa-router/index.d.ts @@ -19,12 +19,6 @@ import * as Koa from "koa"; -declare module "koa" { - interface Context { - params: any; - } -} - declare namespace Router { export interface IRouterOptions { /** @@ -49,7 +43,7 @@ declare namespace Router { strict?: boolean; } - export interface IRouterContext extends Koa.Context { + export interface IRouterContext { /** * url params */ @@ -61,11 +55,11 @@ declare namespace Router { } export interface IMiddleware { - (ctx: Router.IRouterContext, next: () => Promise): any; + (ctx: Koa.ParameterizedContext<{}, IRouterContext>, next: () => Promise): any; } export interface IParamMiddleware { - (param: string, ctx: Router.IRouterContext, next: () => Promise): any; + (param: string, ctx: Koa.ParameterizedContext<{}, IRouterContext>, next: () => Promise): any; } export interface IRouterAllowedMethodsOptions { @@ -88,7 +82,7 @@ declare namespace Router { sensitive?: boolean; strict?: boolean; } - + export interface IUrlOptionsQuery { query: object | string; } @@ -190,19 +184,19 @@ declare class Router { */ put(name: string, path: string | RegExp, ...middleware: Array): Router; put(path: string | RegExp | (string | RegExp)[], ...middleware: Array): Router; - + /** * HTTP link method */ link(name: string, path: string | RegExp, ...middleware: Array): Router; link(path: string | RegExp | (string | RegExp)[], ...middleware: Array): Router; - + /** * HTTP unlink method */ unlink(name: string, path: string | RegExp, ...middleware: Array): Router; unlink(path: string | RegExp | (string | RegExp)[], ...middleware: Array): Router; - + /** * HTTP delete method @@ -283,21 +277,21 @@ declare class Router { /** * Generate URL for route. Takes either map of named `params` or series of * arguments (for regular expression routes) - * + * * router = new Router(); * router.get('user', "/users/:id", ... - * + * * 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: any, options?: Router.IUrlOptionsQuery): string; url(name: string, params: any, options?: Router.IUrlOptionsQuery): Error; From 820145214ba85fac91f8fdfd6d97b9ce617666a0 Mon Sep 17 00:00:00 2001 From: Jan Dolezel Date: Wed, 2 Jan 2019 15:06:56 +0100 Subject: [PATCH 2/2] Opting into typesafe koa --- types/koa-router/koa-router-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/koa-router/koa-router-tests.ts b/types/koa-router/koa-router-tests.ts index e1c90c636d..51e95fb8a5 100644 --- a/types/koa-router/koa-router-tests.ts +++ b/types/koa-router/koa-router-tests.ts @@ -1,7 +1,7 @@ import Koa = require("koa"); import Router = require("koa-router"); -const app = new Koa(); +const app = new Koa<{}, {}>(); const router = new Router({ prefix: "/users"