UNPKG

4.73 kBTypeScriptView Raw
1// Type definitions for Express 4.17
2// Project: http://expressjs.com
3// Definitions by: Boris Yankov <https://github.com/borisyankov>
4// China Medical University Hospital <https://github.com/CMUH>
5// Puneet Arora <https://github.com/puneetar>
6// Dylan Frankland <https://github.com/dfrankland>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8
9/* =================== USAGE ===================
10
11 import express = require("express");
12 var app = express();
13
14 =============================================== */
15
16/// <reference types="express-serve-static-core" />
17/// <reference types="serve-static" />
18
19import * as bodyParser from 'body-parser';
20import * as serveStatic from 'serve-static';
21import * as core from 'express-serve-static-core';
22import * as qs from 'qs';
23
24/**
25 * Creates an Express application. The express() function is a top-level function exported by the express module.
26 */
27declare function e(): core.Express;
28
29declare namespace e {
30 /**
31 * This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser.
32 * @since 4.16.0
33 */
34 var json: typeof bodyParser.json;
35
36 /**
37 * This is a built-in middleware function in Express. It parses incoming requests with Buffer payloads and is based on body-parser.
38 * @since 4.17.0
39 */
40 var raw: typeof bodyParser.raw;
41
42 /**
43 * This is a built-in middleware function in Express. It parses incoming requests with text payloads and is based on body-parser.
44 * @since 4.17.0
45 */
46 var text: typeof bodyParser.text;
47
48 /**
49 * These are the exposed prototypes.
50 */
51 var application: Application;
52 var request: Request;
53 var response: Response;
54
55 /**
56 * This is a built-in middleware function in Express. It serves static files and is based on serve-static.
57 */
58 var static: serveStatic.RequestHandlerConstructor<Response>;
59
60 /**
61 * This is a built-in middleware function in Express. It parses incoming requests with urlencoded payloads and is based on body-parser.
62 * @since 4.16.0
63 */
64 var urlencoded: typeof bodyParser.urlencoded;
65
66 /**
67 * This is a built-in middleware function in Express. It parses incoming request query parameters.
68 */
69 export function query(options: qs.IParseOptions | typeof qs.parse): Handler;
70
71 export function Router(options?: RouterOptions): core.Router;
72
73 interface RouterOptions {
74 /**
75 * Enable case sensitivity.
76 */
77 caseSensitive?: boolean;
78
79 /**
80 * Preserve the req.params values from the parent router.
81 * If the parent and the child have conflicting param names, the child’s value take precedence.
82 *
83 * @default false
84 * @since 4.5.0
85 */
86 mergeParams?: boolean;
87
88 /**
89 * Enable strict routing.
90 */
91 strict?: boolean;
92 }
93
94 interface Application extends core.Application {}
95 interface CookieOptions extends core.CookieOptions {}
96 interface Errback extends core.Errback {}
97 interface ErrorRequestHandler<
98 P = core.ParamsDictionary,
99 ResBody = any,
100 ReqBody = any,
101 ReqQuery = core.Query,
102 Locals extends Record<string, any> = Record<string, any>
103 > extends core.ErrorRequestHandler<P, ResBody, ReqBody, ReqQuery, Locals> {}
104 interface Express extends core.Express {}
105 interface Handler extends core.Handler {}
106 interface IRoute extends core.IRoute {}
107 interface IRouter extends core.IRouter {}
108 interface IRouterHandler<T> extends core.IRouterHandler<T> {}
109 interface IRouterMatcher<T> extends core.IRouterMatcher<T> {}
110 interface MediaType extends core.MediaType {}
111 interface NextFunction extends core.NextFunction {}
112 interface Request<
113 P = core.ParamsDictionary,
114 ResBody = any,
115 ReqBody = any,
116 ReqQuery = core.Query,
117 Locals extends Record<string, any> = Record<string, any>
118 > extends core.Request<P, ResBody, ReqBody, ReqQuery, Locals> {}
119 interface RequestHandler<
120 P = core.ParamsDictionary,
121 ResBody = any,
122 ReqBody = any,
123 ReqQuery = core.Query,
124 Locals extends Record<string, any> = Record<string, any>
125 > extends core.RequestHandler<P, ResBody, ReqBody, ReqQuery, Locals> {}
126 interface RequestParamHandler extends core.RequestParamHandler {}
127 export interface Response<ResBody = any, Locals extends Record<string, any> = Record<string, any>>
128 extends core.Response<ResBody, Locals> {}
129 interface Router extends core.Router {}
130 interface Send extends core.Send {}
131}
132
133export = e;