Skip to content

Commit

Permalink
Fix up express() return type (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey authored Feb 17, 2017
1 parent 3afcfa7 commit 0b8501d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"author": "Felix Becker <[email protected]>",
"license": "ISC",
"devDependencies": {
"tslint": "^3.13.0",
"typescript": "^1.8.10",
"typings": "^1.3.1"
"tslint": "^4.3.1",
"typescript": "^2.1.5",
"typings": "^2.1.0"
}
}
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 0b8501d

Please sign in to comment.