From 480f085d691c65d7e2c67c13017f3fd4522f257f Mon Sep 17 00:00:00 2001 From: Anton Astashov Date: Wed, 6 Feb 2019 21:19:59 -0600 Subject: [PATCH] Explicitly specify `Koa.Middleware` params This way we explicitly state `koa-static` doesn't add anything to Koa's `ctx` or `ctx.state`. It's useful because with those changes it won't erase `ctx.state` type, converting it into `any`. Like, if we have some middleware: ```ts import Koa from 'koa'; type FooCtx = { foo: string }; const someMiddleware: Koa.Middleware = (ctx, next) => { ctx.state.foo = "foo"; } ``` Before the changes in this PR it would be: ```ts const app = new Koa<{}, {}>() .use(someMiddleware) .use(koaStatic(".")) // app is Koa ``` After the changes in this PR: ```ts const app = new Koa<{}, {}>() .use(someMiddleware) .use(koaStatic(".")) // app is Koa ``` --- types/koa-static/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/koa-static/index.d.ts b/types/koa-static/index.d.ts index eaba7866c4..34ebc39d53 100644 --- a/types/koa-static/index.d.ts +++ b/types/koa-static/index.d.ts @@ -19,7 +19,7 @@ import { Middleware } from "koa"; import { SendOptions } from "koa-send"; -declare function serve(root: string, opts?: serve.Options): Middleware; +declare function serve(root: string, opts?: serve.Options): Middleware<{}>; declare namespace serve { interface Options extends SendOptions {