declare Express in ambient environment

This commit is contained in:
Cao, Jiannan
2016-07-12 01:23:42 +08:00
parent 49a98e0443
commit 1f418be731
2 changed files with 8 additions and 7 deletions
-6
View File
@@ -1,6 +0,0 @@
// Type definitions for http-errors-tests.ts
declare namespace Express {
export interface Request {
user?: any
}
}
+8 -1
View File
@@ -1,12 +1,19 @@
/// <reference path="http-errors.d.ts" />
/// <reference path="../express/express.d.ts" />
/// <reference path="../http-errors/http-errors-tests.x.ts" />
import * as createError from 'http-errors';
import * as express from 'express';
var app = express();
declare global {
namespace Express {
export interface Request {
user?: any
}
}
}
app.use(function (req, res, next) {
if (!req.user) return next(createError(401, 'Please login to view this page.'));
next();