Merge pull request #24219 from orblazer/patch-2

[WS] Fix "this" context on "on" functions
This commit is contained in:
Nathan Shively-Sanders
2018-03-28 10:39:37 -07:00
committed by GitHub
+14 -13
View File
@@ -4,6 +4,7 @@
// Matt Silverlock <https://github.com/elithrar>
// Margus Lamp <https://github.com/mlamp>
// Philippe D'Alva <https://github.com/TitaneBoy>
// Orblazer <https://github.com/orblazer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
@@ -67,14 +68,14 @@ declare class WebSocket extends events.EventEmitter {
removeEventListener(method: string, listener?: () => void): void;
// Events
on(event: 'close', listener: (code: number, reason: string) => void): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'upgrade', listener: (request: http.IncomingMessage) => void): this;
on(event: 'message', listener: (data: WebSocket.Data) => void): this;
on(event: 'open' , listener: () => void): this;
on(event: 'ping' | 'pong', listener: (data: Buffer) => void): this;
on(event: 'unexpected-response', listener: (request: http.ClientRequest, response: http.IncomingMessage) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
on(event: 'close', listener: (this: WebSocket, code: number, reason: string) => void): this;
on(event: 'error', listener: (this: WebSocket, err: Error) => void): this;
on(event: 'upgrade', listener: (this: WebSocket, request: http.IncomingMessage) => void): this;
on(event: 'message', listener: (this: WebSocket, data: WebSocket.Data) => void): this;
on(event: 'open' , listener: (this: WebSocket) => void): this;
on(event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void): this;
on(event: 'unexpected-response', listener: (this: WebSocket, request: http.ClientRequest, response: http.IncomingMessage) => void): this;
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
addListener(event: 'close', listener: (code: number, message: string) => void): this;
addListener(event: 'error', listener: (err: Error) => void): this;
@@ -181,11 +182,11 @@ declare namespace WebSocket {
shouldHandle(request: http.IncomingMessage): boolean;
// Events
on(event: 'connection', cb: (socket: WebSocket, request: http.IncomingMessage) => void): this;
on(event: 'error', cb: (error: Error) => void): this;
on(event: 'headers', cb: (headers: string[], request: http.IncomingMessage) => void): this;
on(event: 'listening', cb: () => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
on(event: 'connection', cb: (this: WebSocket, socket: WebSocket, request: http.IncomingMessage) => void): this;
on(event: 'error', cb: (this: WebSocket, error: Error) => void): this;
on(event: 'headers', cb: (this: WebSocket, headers: string[], request: http.IncomingMessage) => void): this;
on(event: 'listening', cb: (this: WebSocket) => void): this;
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
addListener(event: 'connection', cb: (client: WebSocket) => void): this;
addListener(event: 'error', cb: (err: Error) => void): this;