mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #1994 from yortus/open-express.d.ts-interfaces
Open express.d.ts interfaces
This commit is contained in:
Vendored
+14
-3
@@ -12,6 +12,17 @@
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
|
||||
declare module Express {
|
||||
|
||||
// These open interfaces may be extended in an application-specific manner via declaration merging.
|
||||
// See for example passport.d.ts (https://github.com/borisyankov/DefinitelyTyped/blob/master/passport/passport.d.ts)
|
||||
export interface Request { }
|
||||
export interface Response { }
|
||||
export interface Application { }
|
||||
}
|
||||
|
||||
|
||||
declare module "express" {
|
||||
import http = require('http');
|
||||
|
||||
@@ -229,7 +240,7 @@ declare module "express" {
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface Request {
|
||||
interface Request extends Express.Request {
|
||||
|
||||
session: Session;
|
||||
|
||||
@@ -545,7 +556,7 @@ declare module "express" {
|
||||
(body: any): Response;
|
||||
}
|
||||
|
||||
interface Response extends http.ServerResponse {
|
||||
interface Response extends http.ServerResponse, Express.Response {
|
||||
/**
|
||||
* Set status `code`.
|
||||
*
|
||||
@@ -893,7 +904,7 @@ declare module "express" {
|
||||
(req: Request, res: Response, next: Function): any;
|
||||
}
|
||||
|
||||
interface Application extends IRouter<Application> {
|
||||
interface Application extends IRouter<Application>, Express.Application {
|
||||
/**
|
||||
* Initialize the server.
|
||||
*
|
||||
|
||||
@@ -7,7 +7,7 @@ import passport = require('passport');
|
||||
class TestStrategy implements passport.Strategy {
|
||||
public name: string = 'test';
|
||||
constructor() {}
|
||||
authenticate(req: passport.Request) {}
|
||||
authenticate(req: express.Request) {}
|
||||
}
|
||||
|
||||
passport.use(new TestStrategy());
|
||||
@@ -33,7 +33,7 @@ app.post('/login',
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
app.post('/login', function(req: passport.Request, res: passport.Response, next: (err?: any) => void) {
|
||||
app.post('/login', function(req, res, next) {
|
||||
passport.authenticate('local', function(err, user, info) {
|
||||
if (err) { return next(err) }
|
||||
if (!user) {
|
||||
@@ -47,12 +47,12 @@ app.post('/login', function(req: passport.Request, res: passport.Response, next:
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
app.get('/logout', function(req: passport.Request, res: passport.Response) {
|
||||
app.get('/logout', function(req, res) {
|
||||
req.logout();
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
function ensureAuthenticated(req: passport.Request, res: passport.Response, next: (err?: any) => void) {
|
||||
function ensureAuthenticated(req: express.Request, res: express.Response, next: (err?: any) => void) {
|
||||
if (req.isAuthenticated()) { return next(); }
|
||||
if (req.isUnauthenticated()) {
|
||||
res.redirect('/login');
|
||||
|
||||
Vendored
+10
-8
@@ -38,7 +38,16 @@ declare module 'passport' {
|
||||
transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void;
|
||||
}
|
||||
|
||||
interface Request extends express.Request {
|
||||
interface Strategy {
|
||||
name?: string;
|
||||
authenticate(req: express.Request, options?: Object): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module Express {
|
||||
export interface Request {
|
||||
|
||||
// These declarations are merged into express's Request type
|
||||
login(user: any, done: (err: any) => void): void;
|
||||
login(user: any, options: Object, done: (err: any) => void): void;
|
||||
logIn(user: any, done: (err: any) => void): void;
|
||||
@@ -50,11 +59,4 @@ declare module 'passport' {
|
||||
isAuthenticated(): boolean;
|
||||
isUnauthenticated(): boolean;
|
||||
}
|
||||
interface Response extends express.Response {}
|
||||
|
||||
interface Strategy {
|
||||
name?: string;
|
||||
authenticate(req: Request, options?: Object): void;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user