From ce6e288c4d14d66c216b153dd25558e01c6628ed Mon Sep 17 00:00:00 2001 From: Nimish Telang Date: Fri, 15 Jan 2016 16:46:36 +0000 Subject: [PATCH] Update express router type, to work around typescript issue #1805 --- express/express-tests.ts | 20 +++++++++++++++++++- express/express.d.ts | 6 ++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/express/express-tests.ts b/express/express-tests.ts index 72beb0790..de39e2c8a 100644 --- a/express/express-tests.ts +++ b/express/express-tests.ts @@ -21,7 +21,25 @@ app.get('/', function(req, res){ res.send('hello world'); }); -var router = express.Router(); +const router = express.Router(); + + +const pathStr : string = 'test'; +const pathRE : RegExp = /test/; +const path = true? pathStr : pathRE; + +router.get(path); +router.put(path) +router.post(path); +router.delete(path); +router.get(pathStr); +router.put(pathStr) +router.post(pathStr); +router.delete(pathStr); +router.get(pathRE); +router.put(pathRE) +router.post(pathRE); +router.delete(pathRE); router.use((req, res, next) => { next(); }) router.route('/users') diff --git a/express/express.d.ts b/express/express.d.ts index db1981d5d..1a3784049 100644 --- a/express/express.d.ts +++ b/express/express.d.ts @@ -44,8 +44,7 @@ declare module "express" { } interface IRouterMatcher { - (name: string, ...handlers: RequestHandler[]): T; - (name: RegExp, ...handlers: RequestHandler[]): T; + (name: string|RegExp, ...handlers: RequestHandler[]): T; } interface IRouter extends RequestHandler { @@ -881,8 +880,7 @@ declare module "express" { set(setting: string, val: any): Application; get: { (name: string): any; // Getter - (name: string, ...handlers: RequestHandler[]): Application; - (name: RegExp, ...handlers: RequestHandler[]): Application; + (name: string|RegExp, ...handlers: RequestHandler[]): Application; }; /**