MsgBuilder: {
    readonly [K in keyof Spec & string]: Spec[K] extends PayloadMarker<
        infer P,
    >
        ? (payload: P) => Msg<K, P>
        : () => Msg<K>
} & {
    _union: {
        [K in keyof Spec & string]: Spec[K] extends PayloadMarker<infer P>
            ? Msg<K, P>
            : Msg<K>
    }[keyof Spec & string];
}

Variant constructor record returned by defineMsgs. For each tag the spec defined as null, the entry is a zero-arg function returning { kind }. For each tag with a payload marker, the entry takes the payload object and returns { kind, ...payload }.

Type Parameters

Type declaration

  • Readonly_union: {
        [K in keyof Spec & string]: Spec[K] extends PayloadMarker<infer P>
            ? Msg<K, P>
            : Msg<K>
    }[keyof Spec & string]

    Phantom field carrying the closed Msg union for the spec. Read with MsgOf. Always undefined at runtime.

The record also carries a phantom _union field whose type is the closed Msg union for the spec. MsgOf reads that field; it exists only at the type level and is undefined at runtime.