From 2a641a97bf8fa2911807c4ecd53957faab4c581e Mon Sep 17 00:00:00 2001 From: Mathieu Dutour Date: Tue, 1 Aug 2017 10:26:32 -0700 Subject: [PATCH] add microrouter types (#18500) * add microrouter types * add params field to IncomingMessage * fix lint * use micro types for RequestHandler --- types/microrouter/index.d.ts | 29 +++++++++++++++++++++++++++++ types/microrouter/tsconfig.json | 21 +++++++++++++++++++++ types/microrouter/tslint.json | 1 + 3 files changed, 51 insertions(+) create mode 100644 types/microrouter/index.d.ts create mode 100644 types/microrouter/tsconfig.json create mode 100644 types/microrouter/tslint.json diff --git a/types/microrouter/index.d.ts b/types/microrouter/index.d.ts new file mode 100644 index 0000000000..052bd707d3 --- /dev/null +++ b/types/microrouter/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for microrouter 2.2 +// Project: https://github.com/pedronauck/micro-router#readme +// Definitions by: Mathieu Dutour +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { IncomingMessage, ServerResponse, Server } from 'http'; +import { RequestHandler } from 'micro'; + +export type AugmentedRequestHandler = ( + req: IncomingMessage & { + params: {[key: string]: string}, + query: {[key: string]: string} + }, + res: ServerResponse +) => any; + +export type RouteHandler = (path: string, handler: AugmentedRequestHandler) => RequestHandler; + +export function router(...routes: RequestHandler[]): RequestHandler; + +export const get: RouteHandler; +export const post: RouteHandler; +export const put: RouteHandler; +export const patch: RouteHandler; +export const del: RouteHandler; +export const head: RouteHandler; +export const options: RouteHandler; diff --git a/types/microrouter/tsconfig.json b/types/microrouter/tsconfig.json new file mode 100644 index 0000000000..a2cbd4e379 --- /dev/null +++ b/types/microrouter/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts" + ] +} diff --git a/types/microrouter/tslint.json b/types/microrouter/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/microrouter/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }