Created
October 2, 2019 00:49
-
-
Save Ashoat/2dbf10c209a9460f0d0a7c24e3376e6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/definitions/npm/express_v4.x.x/flow_v0.104.x-/express_v4.x.x.js b/definitions/npm/express_v4.x.x/flow_v0.104.x-/express_v4.x.x.js | |
index 84393084..7e29c7e3 100644 | |
--- a/definitions/npm/express_v4.x.x/flow_v0.104.x-/express_v4.x.x.js | |
+++ b/definitions/npm/express_v4.x.x/flow_v0.104.x-/express_v4.x.x.js | |
@@ -98,13 +98,97 @@ declare class express$Response extends http$ServerResponse mixins express$Reques | |
} | |
declare type express$NextFunction = (err?: ?Error | 'route') => mixed; | |
-declare type express$Middleware = | |
- ((req: express$Request, res: express$Response, next: express$NextFunction) => mixed) | | |
- ((error: Error, req: express$Request, res: express$Response, next: express$NextFunction) => mixed); | |
+declare type express$Middleware<Req: express$Request, Res: express$Response> = | |
+ ((req: Req, res: Res, next: express$NextFunction) => mixed) | | |
+ ((error: Error, req: Req, res: Res, next: express$NextFunction) => mixed); | |
declare interface express$RouteMethodType<T> { | |
- (middleware: express$Middleware): T; | |
- (...middleware: Array<express$Middleware>): T; | |
- (path: express$Path|express$Path[], ...middleware: Array<express$Middleware>): T; | |
+ <Req: express$Request, Res: express$Response>( | |
+ middleware: express$Middleware<Req, Res>, | |
+ ): T; | |
+ < | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ ): T; | |
+ < | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ ): T; | |
+ < | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ Req4: express$Request, | |
+ Res4: express$Response, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ): T; | |
+ <Req: express$Request, Res: express$Response>( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req, Res>, | |
+ ): T; | |
+ < | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ ): T; | |
+ < | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ ): T; | |
+ < | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ Req4: express$Request, | |
+ Res4: express$Response, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ): T; | |
+ (...middleware: Array<express$Middleware<mixed, mixed>>): T; | |
+ ( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ ...middleware: Array<express$Middleware<mixed, mixed>> | |
+ ): T; | |
} | |
declare class express$Route { | |
all: express$RouteMethodType<this>; | |
@@ -138,22 +222,138 @@ declare class express$Route { | |
connect: express$RouteMethodType<this>; | |
} | |
-declare class express$Router extends express$Route { | |
+declare class express$Router< | |
+ Req: express$Request, | |
+ Res: express$Response, | |
+> extends express$Route { | |
constructor(options?: express$RouterOptions): void; | |
route(path: string): express$Route; | |
static (options?: express$RouterOptions): express$Router; | |
- use(middleware: express$Middleware): this; | |
- use(...middleware: Array<express$Middleware>): this; | |
- use(path: express$Path|express$Path[], ...middleware: Array<express$Middleware>): this; | |
+ use<Req: express$Request, Res: express$Response>( | |
+ middleware: express$Middleware<Req, Res>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ Req4: express$Request, | |
+ Res4: express$Response, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ Req4: express$Request, | |
+ Res4: express$Response, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ...middlewares: Array<express$Middleware<mixed, mixed>> | |
+ ): this; | |
+ use<Req: express$Request, Res: express$Response>( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware: express$Middleware<Req, Res>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ Req4: express$Request, | |
+ Res4: express$Response, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ): this; | |
+ use< | |
+ Req1: express$Request, | |
+ Res1: express$Response, | |
+ Req2: express$Request, | |
+ Res2: express$Response, | |
+ Req3: express$Request, | |
+ Res3: express$Response, | |
+ Req4: express$Request, | |
+ Res4: express$Response, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ...middlewares: Array<express$Middleware<mixed, mixed>> | |
+ ): this; | |
use(path: string, router: express$Router): this; | |
handle(req: http$IncomingMessage<>, res: http$ServerResponse, next: express$NextFunction): void; | |
- param( | |
+ param<Req: express$Request>( | |
param: string, | |
callback: ( | |
- req: express$Request, | |
+ req: Req, | |
res: express$Response, | |
next: express$NextFunction, | |
- id: string | |
+ value: string, | |
+ paramName: string, | |
) => mixed | |
): void; | |
(req: http$IncomingMessage<>, res: http$ServerResponse, next?: ?express$NextFunction): void; | |
@@ -187,7 +387,10 @@ declare class express$Application extends express$Router mixins events$EventEmit | |
declare module 'express' { | |
declare export type RouterOptions = express$RouterOptions; | |
declare export type CookieOptions = express$CookieOptions; | |
- declare export type Middleware = express$Middleware; | |
+ declare export type Middleware< | |
+ Req: express$Request, | |
+ Res: express$Reseponse, | |
+ > = express$Middleware<Req, Res>; | |
declare export type NextFunction = express$NextFunction; | |
declare export type RequestParams = express$RequestParams; | |
declare export type $Response = express$Response; | |
@@ -198,7 +401,7 @@ declare module 'express' { | |
// If you try to call like a function, it will use this signature | |
(): express$Application, | |
// `static` property on the function | |
- static: (root: string, options?: Object) => express$Middleware, | |
+ static: <Req: express$Request>(root: string, options?: Object) => express$Middleware<Req>, | |
// `Router` property on the function | |
Router: typeof express$Router, | |
... | |
diff --git a/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_overrideUseMethodClassExtension.js b/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_overrideUseMethodClassExtension.js | |
index 525b9198..1b988935 100644 | |
--- a/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_overrideUseMethodClassExtension.js | |
+++ b/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_overrideUseMethodClassExtension.js | |
@@ -14,16 +14,123 @@ declare type test_express$CustomPath = string | RegExp; | |
declare type test_express$CustomNextFunction = express$NextFunction; | |
-declare type test_express$CustomMiddleware = | |
- ((req: test_express$CustomRequest, res: test_express$CustomResponse, next: test_express$CustomNextFunction) => mixed) | | |
- ((error: Error, req: test_express$CustomRequest, res: test_express$CustomResponse, next: test_express$CustomNextFunction) => mixed); | |
- | |
declare class test_express$CustomApplication extends express$Application { | |
constructor(expressConstructor: () => express$Application): this; | |
- use(middleware: test_express$CustomMiddleware): this; | |
- use(...middleware: Array<test_express$CustomMiddleware>): this; | |
- use(path: test_express$CustomPath|test_express$CustomPath[], ...middleware: Array<test_express$CustomMiddleware>): this; | |
- use(path: string, router: express$Router): this; | |
+ use<Req: test_express$CustomRequest, Res: test_express$CustomResponse>( | |
+ middleware: express$Middleware<Req, Res>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ Req3: test_express$CustomRequest, | |
+ Res3: test_express$CustomResponse, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ Req3: test_express$CustomRequest, | |
+ Res3: test_express$CustomResponse, | |
+ Req4: test_express$CustomRequest, | |
+ Res4: test_express$CustomResponse, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ Req3: test_express$CustomRequest, | |
+ Res3: test_express$CustomResponse, | |
+ Req4: test_express$CustomRequest, | |
+ Res4: test_express$CustomResponse, | |
+ >( | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ...middlewares: Array<express$Middleware<mixed, mixed>> | |
+ ): this; | |
+ use<Req: test_express$CustomRequest, Res: test_express$CustomResponse>( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware: express$Middleware<Req, Res>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ Req3: test_express$CustomRequest, | |
+ Res3: test_express$CustomResponse, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ Req3: test_express$CustomRequest, | |
+ Res3: test_express$CustomResponse, | |
+ Req4: test_express$CustomRequest, | |
+ Res4: test_express$CustomResponse, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ): this; | |
+ use< | |
+ Req1: test_express$CustomRequest, | |
+ Res1: test_express$CustomResponse, | |
+ Req2: test_express$CustomRequest, | |
+ Res2: test_express$CustomResponse, | |
+ Req3: test_express$CustomRequest, | |
+ Res3: test_express$CustomResponse, | |
+ Req4: test_express$CustomRequest, | |
+ Res4: test_express$CustomResponse, | |
+ >( | |
+ path: express$Path | $ReadOnlyArray<express$Path>, | |
+ middleware1: express$Middleware<Req1, Res1>, | |
+ middleware2: express$Middleware<Req2, Res2>, | |
+ middleware3: express$Middleware<Req3, Res3>, | |
+ middleware4: express$Middleware<Req4, Res4>, | |
+ ...middlewares: Array<express$Middleware<mixed, mixed>> | |
+ ): this; | |
} | |
// Class Extensions: Test Functions | |
@@ -31,7 +138,11 @@ function test_express$CustomApplication( | |
expressConstructor: () => express$Application | |
) { | |
const express = expressConstructor(); | |
- express.use((req: any, res: any, next: express$NextFunction) => { | |
+ express.use(( | |
+ req: test_express$CustomRequest, | |
+ res: test_express$CustomResponse, | |
+ next: express$NextFunction, | |
+ ) => { | |
// Private Constructor Mutation: Add new properties | |
req.foo = 'hello'; | |
res.bar = 'goodbye'; | |
diff --git a/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_response.js b/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_response.js | |
index b604c403..3514604e 100644 | |
--- a/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_response.js | |
+++ b/definitions/npm/express_v4.x.x/flow_v0.104.x-/test_response.js | |
@@ -27,6 +27,18 @@ app.use( | |
); | |
app.post("/post-router-callable", router); | |
+// Can set a custom param on request | |
+app.param('test', ( | |
+ req: express$Request & { testValue: string, ... }, | |
+ res: express$Response, | |
+ next: express$NextFunction, | |
+ id: string, | |
+ paramName: string, | |
+) => { | |
+ req.testValue = id; | |
+ next(); | |
+}); | |
+ | |
// Can use an express app directly as a server listener | |
const httpServer = http.createServer(app); | |
httpServer.listen(9000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment