From ded79672a7a0471faaeb9bdf6f4810e079f296a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Sun, 10 Dec 2017 00:18:25 +0100 Subject: [PATCH] koa-static v4.0 --- types/koa-send/index.d.ts | 2 +- types/koa-static/index.d.ts | 44 ++++++++-------------------- types/koa-static/koa-static-tests.ts | 6 ++-- 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/types/koa-send/index.d.ts b/types/koa-send/index.d.ts index 65228c9981..a4b090e1ea 100644 --- a/types/koa-send/index.d.ts +++ b/types/koa-send/index.d.ts @@ -29,7 +29,7 @@ declare namespace send { /** Root directory to restrict file access. (defaults to '') */ root?: string; /** Name of the index file to serve automatically when visiting the root location. (defaults to none) */ - index?: string; + index?: string | false; /** Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. (defaults to true). */ gzip?: boolean; /** Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists. (defaults to true). */ diff --git a/types/koa-static/index.d.ts b/types/koa-static/index.d.ts index 6395efec3a..eaba7866c4 100644 --- a/types/koa-static/index.d.ts +++ b/types/koa-static/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for koa-static 3.0 +// Type definitions for koa-static 4.0 // Project: https://github.com/koajs/static // Definitions by: Jerry Chin -// Definitions: https://github.com/hellopao/DefinitelyTyped +// Tomek Łaziuk +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /* =================== USAGE =================== @@ -14,38 +15,17 @@ =============================================== */ -import * as Koa from "koa"; +import { Middleware } from "koa"; -declare function serve(root: string, opts?: { - /** - * Default file name, defaults to 'index.html' - */ - index?: boolean | string; +import { SendOptions } from "koa-send"; - /** - * If true, serves after return next(),allowing any downstream middleware to respond first. - */ - defer?: boolean; +declare function serve(root: string, opts?: serve.Options): Middleware; - /** - * Browser cache max-age in milliseconds. defaults to 0 - */ - maxage?: number; +declare namespace serve { + interface Options extends SendOptions { + /** If true, serves after return next(), allowing any downstream middleware to respond first. */ + defer?: boolean; + } +} - /** - * Allow transfer of hidden files. defaults to false - */ - hidden?: boolean; - - /** - * Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true. - */ - gzip?: boolean; - - /** - * Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to `false`) - */ - extensions?: string[]; -}): Koa.Middleware; -declare namespace serve {} export = serve; diff --git a/types/koa-static/koa-static-tests.ts b/types/koa-static/koa-static-tests.ts index 2bcb0ae030..9b0d756f7d 100644 --- a/types/koa-static/koa-static-tests.ts +++ b/types/koa-static/koa-static-tests.ts @@ -4,9 +4,9 @@ import serve = require("koa-static"); const app = new Koa(); app.use(serve('.', { - index: false, - defer: false, - extensions: ['html'] + index: false, + defer: false, + extensions: ['html'], })); app.listen(80);