mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-08 03:00:02 +00:00
Fix ws type definitions (#41905)
* Make `url.URL` a valid type for the `address` parameter * Fix `this` type on server event listeners
This commit is contained in:
14
types/ws/index.d.ts
vendored
14
types/ws/index.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user