Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions types/ws/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// teidesu <https://github.com/teidesu>
// Bartosz Wojtkowiak <https://github.com/wojtkowiak>
// Kyle Hensel <https://github.com/k-yle>
// Samuel Skeen <https://github.com/cwadrupldijjit>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />
Expand Down Expand Up @@ -171,7 +172,7 @@ declare class WebSocket extends EventEmitter {
}

declare const WebSocketAlias: typeof WebSocket;
type WebSocketAlias = WebSocket;
interface WebSocketAlias extends WebSocket {} // tslint:disable-line no-empty-interface

declare namespace WebSocket {
/**
Expand Down Expand Up @@ -347,9 +348,9 @@ declare namespace WebSocket {
}

const WebSocketServer: typeof Server;
type WebSocketServer = Server;
interface WebSocketServer extends Server {} // tslint:disable-line no-empty-interface
const WebSocket: typeof WebSocketAlias;
type WebSocket = WebSocketAlias;
interface WebSocket extends WebSocketAlias {} // tslint:disable-line no-empty-interface

// WebSocket stream
function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
Expand Down
21 changes: 21 additions & 0 deletions types/ws/ws-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,24 @@ function f() {
}
});
}

declare module 'ws' {
interface WebSocket {
id?: string;
}

interface Server {
getWebSocketId(): string;
}
}

{
const server = new wslib.WebSocketServer();

server.on('connection', (ws) => {
// $ExpectType string | undefined
ws.id;

ws.id = server.getWebSocketId();
});
}