Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up express() return type #19

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}