Skip to Content
TypeScript

TypeScript

Event Type Definition

Define the shape of an event received from the WebSocket channel.

type MessageReceivedEvent = { userId: string; message: string, ts: string; } type PollStartedEvent = { userId: string; choices: string[]; ts: string; }

Channel Declaration

Extend the websocketkit module to declare a strongly typed channel. This allows WsKit to infer event and parameter types when subscribing.

declare module 'websocketkit' { interface ChannelRegistry { 'chats.$chatId': { type: 'presence'; params: { chatId: number }, events: { messageReceived: MessageReceivedEvent, pollStarted: PollStartedEvent } }; } }