From b4b8c2f7d35d7fb25c184b2f2d2ed9d4dc457f72 Mon Sep 17 00:00:00 2001 From: York Yao Date: Mon, 9 Oct 2017 17:36:57 -0500 Subject: [PATCH] add types of http-server (#20394) * add types of http-server * add strictFunctionTypes * fix lint --- types/http-server/http-server-tests.ts | 6 ++++++ types/http-server/index.d.ts | 30 ++++++++++++++++++++++++++ types/http-server/tsconfig.json | 23 ++++++++++++++++++++ types/http-server/tslint.json | 1 + 4 files changed, 60 insertions(+) create mode 100644 types/http-server/http-server-tests.ts create mode 100644 types/http-server/index.d.ts create mode 100644 types/http-server/tsconfig.json create mode 100644 types/http-server/tslint.json diff --git a/types/http-server/http-server-tests.ts b/types/http-server/http-server-tests.ts new file mode 100644 index 0000000000..8e6be14578 --- /dev/null +++ b/types/http-server/http-server-tests.ts @@ -0,0 +1,6 @@ +import { createServer } from "http-server"; + +const server = createServer(); +server.listen(8000); + +server.close(); diff --git a/types/http-server/index.d.ts b/types/http-server/index.d.ts new file mode 100644 index 0000000000..97b4739604 --- /dev/null +++ b/types/http-server/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for http-server 0.10 +// Project: https://github.com/indexzero/http-server#readme +// Definitions by: York Yao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as http from "http"; +import * as https from "https"; +import { HandleFunction } from "connect"; + +export function createServer(options?: Options): http.Server | https.Server; + +export interface Options { + root?: string; + headers?: { [name: string]: string }; + cache?: number; + showDir?: boolean | "false"; + autoIndex?: boolean | "false"; + showDotfiles?: boolean; + gzip?: boolean; + contentType?: string; + ext?: boolean; + before?: HandleFunction[]; + // tslint:disable-next-line prefer-method-signature + logFn?: (req: http.IncomingMessage, res: http.ServerResponse, err: Error) => void; + cors?: boolean; + corsHeaders?: string; + robots?: string | true; + proxy?: string; + https?: https.ServerOptions; +} diff --git a/types/http-server/tsconfig.json b/types/http-server/tsconfig.json new file mode 100644 index 0000000000..98f006389c --- /dev/null +++ b/types/http-server/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "http-server-tests.ts" + ] +} diff --git a/types/http-server/tslint.json b/types/http-server/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/http-server/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }