-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeclarations.d.ts
80 lines (70 loc) · 1.86 KB
/
declarations.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
declare module 'router' {
import { NextFunction, NextHandleFunction } from 'connect';
import { IncomingMessage, ServerResponse } from 'http';
export type Path = string | RegExp | Array<string | RegExp>;
export namespace Router {
export interface RouteType {
new (path: string): Route;
prototype: Route;
}
type Method =
| 'all'
| 'head'
| 'get'
| 'post'
| 'delete'
| 'put'
| 'patch'
| 'options';
export type Route = { readonly path: Path } & Record<
Method,
(
middleware: NextHandleFunction,
...middlewares: NextHandleFunction[]
) => Route
>;
export interface Options {
caseSensitive?: boolean;
strict?: boolean;
mergeParams?: <C extends {}, P extends {}>(
currentParams: C,
parentParams: P,
) => Record<string | number, any>;
}
export type ParamCallback<K = string | number> = (
req: IncomingMessage,
res: ServerResponse,
next: NextFunction,
value: any,
name: K,
) => any;
interface InnerRouter extends NextHandleFunction {
route(path: Path): Route;
param: <K extends string | number>(name: K, fn: ParamCallback<K>) => this;
}
export type Router = InnerRouter &
Record<
'use' | Method,
{
(
path: Path,
middleware: NextHandleFunction,
...middlewares: NextHandleFunction[]
): Router;
(
middleware: NextHandleFunction,
...middlewares: NextHandleFunction[]
): Router;
}
>;
interface RouterType {
new (options?: Options): Router;
(options?: Options): Router;
Route: RouteType;
prototype: Router;
}
}
export type RouterType = Router.RouterType;
const Router: RouterType;
export default Router;
}