diff --git a/types/ws/index.d.ts b/types/ws/index.d.ts index 1fbf6b7da57af3..6329f2cb2f4923 100644 --- a/types/ws/index.d.ts +++ b/types/ws/index.d.ts @@ -56,14 +56,23 @@ declare class WebSocket extends events.EventEmitter { terminate(): void; // HTML5 WebSocket events - addEventListener(method: 'message', cb?: (event: { data: any; type: string; target: WebSocket }) => void): void; - addEventListener(method: 'close', cb?: (event: { + addEventListener(method: 'message', cb: (event: { + data: any; + type: string; + target: WebSocket + }, options?: WebSocket.EventListenerOptions) => void): void; + addEventListener(method: 'close', cb: (event: { wasClean: boolean; code: number; reason: string; target: WebSocket - }) => void): void; - addEventListener(method: 'error', cb?: (event: {error: any, message: any, type: string, target: WebSocket }) => void): void; - addEventListener(method: 'open', cb?: (event: { target: WebSocket }) => void): void; - addEventListener(method: string, listener?: () => void): void; + }, options?: WebSocket.EventListenerOptions) => void): void; + addEventListener(method: 'error', cb: (event: { + error: any, + message: any, + type: string, + target: WebSocket + }, options?: WebSocket.EventListenerOptions) => void): void; + addEventListener(method: 'open', cb: (event: { target: WebSocket }) => void, options?: WebSocket.EventListenerOptions): void; + addEventListener(method: string, listener: () => void, options?: WebSocket.EventListenerOptions): void; removeEventListener(method: 'message', cb?: (event: { data: any; type: string; target: WebSocket }) => void): void; removeEventListener(method: 'close', cb?: (event: { @@ -192,6 +201,10 @@ declare namespace WebSocket { target: WebSocket; } + interface EventListenerOptions { + once?: boolean; + } + interface ServerOptions { host?: string; port?: number; diff --git a/types/ws/ws-tests.ts b/types/ws/ws-tests.ts index efa244afd50cbc..6058c4d234c1f0 100644 --- a/types/ws/ws-tests.ts +++ b/types/ws/ws-tests.ts @@ -158,3 +158,10 @@ import * as url from 'url'; duplex.pipe(process.stdout); process.stdin.pipe(duplex); } + +{ + const ws = new WebSocket('ws://www.host.com/path'); + ws.addEventListener('other', () => {}); + ws.addEventListener('other', () => {}, { once: true }); + ws.addEventListener('other', () => {}, { once: true }); +}