diff --git a/types/ws/index.d.ts b/types/ws/index.d.ts index 859c0d487c..ae6139cbfc 100644 --- a/types/ws/index.d.ts +++ b/types/ws/index.d.ts @@ -43,8 +43,8 @@ declare class WebSocket extends events.EventEmitter { onclose: (event: WebSocket.CloseEvent) => void; onmessage: (event: WebSocket.MessageEvent) => void; - constructor(address: string, options?: WebSocket.ClientOptions); - constructor(address: string, protocols?: string | string[], options?: WebSocket.ClientOptions); + constructor(address: string | url.URL, options?: WebSocket.ClientOptions); + constructor(address: string | url.URL, protocols?: string | string[], options?: WebSocket.ClientOptions); close(code?: number, data?: string): void; ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void; @@ -231,11 +231,11 @@ declare namespace WebSocket { shouldHandle(request: http.IncomingMessage): boolean; // Events - 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: 'close' | 'listening', cb: (this: WebSocket) => void): this; - on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this; + on(event: 'connection', cb: (this: Server, socket: WebSocket, request: http.IncomingMessage) => void): this; + on(event: 'error', cb: (this: Server, error: Error) => void): this; + on(event: 'headers', cb: (this: Server, headers: string[], request: http.IncomingMessage) => void): this; + on(event: 'close' | 'listening', cb: (this: Server) => void): this; + on(event: string | symbol, listener: (this: Server, ...args: any[]) => void): this; addListener(event: 'connection', cb: (client: WebSocket) => void): this; addListener(event: 'error', cb: (err: Error) => void): this; diff --git a/types/ws/ws-tests.ts b/types/ws/ws-tests.ts index 9e7576d911..6ec74c05ba 100644 --- a/types/ws/ws-tests.ts +++ b/types/ws/ws-tests.ts @@ -10,7 +10,7 @@ import * as url from 'url'; } { - const addr = 'ws://www.host.com/path'; + const addr = new url.URL('ws://www.host.com/path'); const ws = new WebSocket(addr); ws.on('open', () => { const array = new Float32Array(5);