Skip to main content

BatchEvent

@rotorsoft/act-root


@rotorsoft/act-root / act/src / BatchEvent

Type Alias: BatchEvent<TEvents>

BatchEvent<TEvents> = { [K in keyof TEvents]: Committed<TEvents, K> }[keyof TEvents]

Defined in: libs/act/src/types/reaction.ts:150

Distributive mapped type that produces a proper discriminated union of committed events. Unlike Committed<TEvents, keyof TEvents> (where name and data are independent unions), each variant correlates name with its corresponding data — enabling switch (event.name) to narrow both fields correctly.

Type Parameters

TEvents

TEvents extends Schemas

Event schemas

Example

for (const event of events) {
switch (event.name) {
case "TicketOpened":
event.data; // typed as TicketOpened's schema
break;
case "TicketClosed":
event.data; // typed as TicketClosed's schema
break;
default:
const _: never = event; // compile error if a case is missing
}
}