interface WebSocketEventMap
Interface mapping WebSocket
event names to their corresponding event types.
Used for strongly typed event handling with addEventListener
and removeEventListener
.
Examples #
#
// Using with TypeScript for strongly-typed event handling
const ws = new WebSocket("ws://localhost:8080");
ws.addEventListener("open", (event) => {
console.log("Connection established");
});
ws.addEventListener("message", (event: MessageEvent) => {
console.log(`Received: ${event.data}`);
});