Skip to content

Commit 9d43645

Browse files
author
Maxime LUCE
committed
Fix typings issues
1 parent 962ede5 commit 9d43645

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

connect/connect-tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import * as connect from "connect";
66
const app = connect();
77

88
// log all requests
9-
app.use((req, res, next) => {
9+
app.use((req: http.IncomingMessage, res: http.ServerResponse, next: Function) => {
1010
console.log(req, res);
1111
next();
1212
});
1313

1414
// Stop on errors
15-
app.use((err, req, res, next) => {
15+
app.use((err: Error, req: http.IncomingMessage, res: http.ServerResponse, next: Function) => {
1616
if (err) {
1717
return res.end(`Error: ${err}`);
1818
}
@@ -21,7 +21,7 @@ app.use((err, req, res, next) => {
2121
});
2222

2323
// respond to all requests
24-
app.use((req, res) => {
24+
app.use((req: http.IncomingMessage, res: http.ServerResponse) => {
2525
res.end("Hello from Connect!\n");
2626
});
2727

connect/connect.d.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for connect v3.4.0.
1+
// Type definitions for connect v3.4.0
22
// Project: https://github.com/senchalabs/connect
33
// Definitions by: Maxime LUCE <https://github.com/SomaticIT/>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -16,20 +16,19 @@ declare module "connect" {
1616

1717
module createServer {
1818
export type ServerHandle = HandleFunction | http.Server;
19-
20-
export interface HandleFunction {
21-
(req: http.IncomingMessage, res: http.ServerResponse): void;
22-
(req: http.IncomingMessage, res: http.ServerResponse, next: Function): void;
23-
(err: Error, req: http.IncomingMessage, res: http.ServerResponse, next: Function): void;
24-
}
19+
20+
export type SimpleHandleFunction = (req: http.IncomingMessage, res: http.ServerResponse) => void;
21+
export type NextHandleFunction = (req: http.IncomingMessage, res: http.ServerResponse, next: Function) => void;
22+
export type ErrorHandleFunction = (err: Error, req: http.IncomingMessage, res: http.ServerResponse, next: Function) => void;
23+
export type HandleFunction = SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction;
2524

2625
export interface ServerStackItem {
2726
route: string;
2827
handle: ServerHandle;
2928
}
3029

3130
export interface Server extends NodeJS.EventEmitter {
32-
(req: http.IncomingMessage, res: http.ServerResponse, next: Function) => void;
31+
(req: http.IncomingMessage, res: http.ServerResponse, next?: Function): void;
3332

3433
route: string;
3534
stack: ServerStackItem[];

0 commit comments

Comments
 (0)