Skip to content

Commit

Permalink
Fix up express() return type
Browse files Browse the repository at this point in the history
Modifying the prototype is part of middleware in Express, that's how it accepts raw HTTP.
  • Loading branch information
blakeembrey committed Jan 15, 2017
1 parent 3afcfa7 commit 6d0fc21
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 1 addition & 3 deletions lib/application.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

import {Server} from 'http';
import {ListenOptions} from 'net';
import {EventEmitter} from 'events';
import {Router, ParamHandler, HandlerArgument, PathArgument} from './router/index';

declare namespace app {
export interface Application extends EventEmitter, Router {

export interface Application extends Router {
/**
* Contains one or more path patterns on which a sub-app was mounted.
*/
Expand Down
8 changes: 7 additions & 1 deletion lib/express.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import {IncomingMessage, ServerResponse} from 'http';
import {EventEmitter} from 'events';
import {Application as _Application} from './application';
import {Request as _Request} from './request';
import {Response as _Response, CookieOptions as _CookieOptions} from './response';
Expand All @@ -21,12 +23,16 @@ declare namespace createApplication {
export type Handler = createRouter.Handler
export type NextFunction = createRouter.NextFunction

export interface Server extends Application, EventEmitter {
(req: IncomingMessage, res: ServerResponse, next?: (err?: Error) => void): void;
}

// need to use an interface for this because `static` is a reserved word
// and cannot be used as a variable identifier
export interface Express {

/** Create an express application. */
(): Application;
(): Server;

/** The Application prototype */
application: Application;
Expand Down
5 changes: 4 additions & 1 deletion test/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

import express = require('express');
import {createServer} from 'http';
import router from './router';

const app: express.Application = express();
const app = express();

createServer(app).listen(3000);

// requesthandler
const requestHandler: express.RequestHandler = (req, res, next) => {
Expand Down
9 changes: 3 additions & 6 deletions typings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"name": "express",
"main": "index.d.ts",
"version": "4.14.0",
"homepage": "https://github.com/types/npm-express",
"dependencies": {
"path-to-regexp": "github:pillarjs/path-to-regexp/index.d.ts#ec285ed3500aed455df59e3b8b07f473412918a4",
"serve-static": "registry:npm/serve-static#1.11.1+20160810053450"
"serve-static": "registry:npm/serve-static#1.11.1+20161113104247"
},
"version": "4.14.0",
"globalDependencies": {
"node": "registry:env/node#6.0.0+20160723033700"
},
"globalDevDependencies": {
"node": "registry:env/node#6.0.0+20160902022231"
"node": "registry:env/node#6.0.0+20170115054122"
}
}

0 comments on commit 6d0fc21

Please sign in to comment.