DefinitelyTyped/types/koa-static/index.d.ts
Anton Astashov 480f085d69 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<FooCtx, {}> = (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<any, {}>
```

After the changes in this PR:

```ts
const app = new Koa<{}, {}>()
  .use(someMiddleware)
  .use(koaStatic("."))
// app is Koa<FooCtx, {}>
```
2019-02-06 21:43:11 -06:00

32 lines
905 B
TypeScript

// Type definitions for koa-static 4.0
// Project: https://github.com/koajs/static
// Definitions by: Jerry Chin <https://github.com/hellopao>
// Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/* =================== USAGE ===================
import serve = require("koa-static");
var Koa = require('koa');
var app = new Koa();
app.use(serve("."));
=============================================== */
import { Middleware } from "koa";
import { SendOptions } from "koa-send";
declare function serve(root: string, opts?: serve.Options): Middleware<{}>;
declare namespace serve {
interface Options extends SendOptions {
/** If true, serves after return next(), allowing any downstream middleware to respond first. */
defer?: boolean;
}
}
export = serve;