Merge pull request #7965 from aleung/express

express.d.ts: define next() function type
This commit is contained in:
Masahiro Wakame
2016-02-07 01:50:46 +09:00
2 changed files with 23 additions and 5 deletions
+13
View File
@@ -17,6 +17,12 @@ app.use(function(req, res, next){
next();
});
app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
console.error(err);
next(err);
});
app.get('/', function(req, res){
res.send('hello world');
});
@@ -47,6 +53,13 @@ router.route('/users')
res.send(req.query['token']);
});
router.get('/user/:id', function(req, res, next) {
if (req.params.id == 0) next('route');
else next();
}, function(req, res, next) {
res.render('regular');
});
app.use((req, res, next) => {
// hacky trick, router is just a handler
router(req, res, next);
+10 -5
View File
@@ -407,9 +407,9 @@ declare module "express" {
originalUrl: string;
url: string;
baseUrl: string;
app: Application;
}
@@ -796,18 +796,23 @@ declare module "express" {
charset: string;
}
interface NextFunction {
(): void;
(err: any): void;
}
interface ErrorRequestHandler {
(err: any, req: Request, res: Response, next: Function): any;
(err: any, req: Request, res: Response, next: NextFunction): any;
}
interface RequestHandler {
(req: Request, res: Response, next: Function): any;
(req: Request, res: Response, next: NextFunction): any;
}
interface Handler extends RequestHandler {}
interface RequestParamHandler {
(req: Request, res: Response, next: Function, param: any): any;
(req: Request, res: Response, next: NextFunction, param: any): any;
}
interface Application extends IRouter<Application>, Express.Application {