7
7
8
8
/// <reference types="node" />
9
9
10
+ import { RequestHandler } from 'express' ;
11
+ import { Params , ParamsDictionary , Query } from 'express-serve-static-core' ;
10
12
import { IncomingMessage , Server , ServerResponse } from 'http' ;
11
13
import * as Trouter from 'trouter' ;
12
14
import { Url } from 'url' ;
@@ -15,7 +17,7 @@ declare namespace polka {
15
17
/**
16
18
* A middleware function
17
19
*/
18
- type Middleware = ( req : IncomingMessage , res : ServerResponse , next : Next ) => void | Promise < void > ;
20
+ type Middleware < P extends Params = ParamsDictionary , ResBody = any , ReqBody = any , ReqQuery = Query > = RequestHandler < P , ResBody , ReqBody , ReqQuery > ;
19
21
20
22
/**
21
23
* Calls the next middleware function in the chain, or throws an error.
@@ -59,7 +61,7 @@ declare namespace polka {
59
61
/**
60
62
* An instance of the Polka router.
61
63
*/
62
- interface Polka extends Trouter < Middleware > {
64
+ interface Polka extends Trouter < RequestHandler > {
63
65
/**
64
66
* Parses the `req.url` property of the given request.
65
67
*/
@@ -69,13 +71,13 @@ declare namespace polka {
69
71
* Attach middleware(s) and/or sub-application(s) to the server.
70
72
* These will execute before your routes' handlers.
71
73
*/
72
- use ( ...handlers : Middleware [ ] ) : this;
74
+ use ( ...handlers : RequestHandler [ ] ) : this;
73
75
74
76
/**
75
77
* Attach middleware(s) and/or sub-application(s) to the server.
76
78
* These will execute before your routes' handlers.
77
79
*/
78
- use ( pattern : string | RegExp , ...handlers : Middleware [ ] | Polka [ ] ) : this;
80
+ use ( pattern : string | RegExp , ...handlers : RequestHandler [ ] | Polka [ ] ) : this;
79
81
80
82
/**
81
83
* Boots (or creates) the underlying `http.Server` for the first time.
0 commit comments