Skip to content

Commit

Permalink
Explicitly specify Koa.Middleware params in typings
Browse files Browse the repository at this point in the history
This way we explicitly state `koa-body` 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<FooCtx, {}> = (ctx, next) => {
    ctx.state.foo = "foo";
}
```

Before the changes in this PR it would be:

```ts
const app = new Koa<{}, {}>()
    .use(someMiddleware)
    .use(koaBody())
// app is Koa<any, {}>
```

After the changes in this PR:

```ts
const app = new Koa<{}, {}>()
  .use(someMiddleware)
  .use(koaBody())
// app is Koa<FooCtx, {}>
```
  • Loading branch information
Anton Astashov committed Jan 31, 2019
1 parent 6f7cba4 commit f848362
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -152,6 +152,6 @@ declare namespace koaBody {
}
}

declare function koaBody (options?: koaBody.IKoaBodyOptions): Koa.Middleware;
declare function koaBody (options?: koaBody.IKoaBodyOptions): Koa.Middleware<{}, {}>;

export = koaBody;

0 comments on commit f848362

Please sign in to comment.