Skip to content

getChannel

getChannel<TMap>(name): Channel<TMap>

Defined in: packages/postal/src/channel.ts:745

Gets or creates a singleton channel by name.

The first call with a given name creates the channel. Subsequent calls return the same instance. The type map generic is compile-time only — all call sites referencing the same channel name should use the same map.

Two ways to type a channel:

  1. Explicit type map — pass TMap directly:

    const ch = getChannel<MyTopicMap>("orders");
  2. Registry augmentation — declare once, infer everywhere:

    declare module "postal" {
      interface ChannelRegistry { orders: MyTopicMap }
    }
    const ch = getChannel("orders"); // MyTopicMap inferred

TMap extends Record<string, unknown>

string

The channel name (defaults to "__default__")

Channel<TMap>

The singleton channel instance

getChannel<TName>(name?): Channel<ResolveChannelMap<TName>>

Defined in: packages/postal/src/channel.ts:746

Gets or creates a singleton channel by name.

The first call with a given name creates the channel. Subsequent calls return the same instance. The type map generic is compile-time only — all call sites referencing the same channel name should use the same map.

Two ways to type a channel:

  1. Explicit type map — pass TMap directly:

    const ch = getChannel<MyTopicMap>("orders");
  2. Registry augmentation — declare once, infer everywhere:

    declare module "postal" {
      interface ChannelRegistry { orders: MyTopicMap }
    }
    const ch = getChannel("orders"); // MyTopicMap inferred

TName extends string = "__default__"

TName

The channel name (defaults to "__default__")

Channel<ResolveChannelMap<TName>>

The singleton channel instance