Skip to main content
zerotal

Documentation


Documentation / @zerotal/broadcasting / BroadcastChannelMap

Type Alias: BroadcastChannelMap

BroadcastChannelMap = Record<string, Record<string, object>>

Defined in: broadcasting/src/TypedBroadcastManager.ts:39

Shape of a typed broadcast channel map.

Keys are channel name patterns (may include [param] placeholders). Values are objects mapping event names to their payload types.

Example

export interface Channels extends BroadcastChannelMap {
  'posts': {
    PostCreated: { id: number; title: string };
    PostDeleted: { id: number };
  };
  'private-orders.[orderId]': {
    OrderShipped: { orderId: number; trackingCode: string };
    OrderCancelled: { orderId: number; reason: string };
  };
  'presence-room.[roomId]': {
    MessageSent: { userId: number; text: string };
  };
}

const manager = new TypedBroadcastManager<Channels>();

// Static channel — fully typed
manager.to('posts', 'PostCreated', { id: 1, title: 'Hello' });

// Parameterised channel — pass the pattern + params separately
manager.toChannel('private-orders.[orderId]', { orderId: 42 }, 'OrderShipped', {
  orderId: 42,
  trackingCode: 'UPS-123',
});