EventKey
Defined in: src/EventKey.ts:64
Named, type-tagged identity for a kind-discriminated event — the
EventStream counterpart to ServiceKey. Two keys are equal iff
their kind matches; the type parameter is a compile-time marker that lets
a subscription’s predicate see the event’s real shape without the caller
restating it.
The field is kind, not id: it is compared against the event’s own kind,
the project-wide discriminant, and a second name for the same string would
be drift waiting to happen.
A type and a const of the same name give a plain event the call shape a
class channel gets for free:
export type UserLoggedInEvent = { readonly kind: 'user-logged-in'; readonly userId: string };export const UserLoggedInEvent = EventKey.of<UserLoggedInEvent>('user-logged-in');
eventStream.subscribe(self, UserLoggedInEvent, (event) => event.userId !== 'system');eventStream.publish({ kind: 'user-logged-in', userId: 'user-42' });The explicit type argument is load-bearing. EventKey.of('user-logged-in')
infers EventKey<{ kind: string }> from the constraint, and every predicate
written against that key sees { kind: string } instead of the event.
Type Parameters
Section titled “Type Parameters”TEvent
Section titled “TEvent”TEvent = unknown
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EventKey<
TEvent>(kind):EventKey<TEvent>
Defined in: src/EventKey.ts:68
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”EventKey<TEvent>
Properties
Section titled “Properties”_event
Section titled “_event”
readonly_event:TEvent
Defined in: src/EventKey.ts:66
Phantom field — retains TEvent so inference round-trips through the key.
readonlykind:string
Defined in: src/EventKey.ts:68
Methods
Section titled “Methods”equals()
Section titled “equals()”equals(
other):boolean
Defined in: src/EventKey.ts:81
Parameters
Section titled “Parameters”EventKey
Returns
Section titled “Returns”boolean
toString()
Section titled “toString()”toString():
string
Defined in: src/EventKey.ts:82
Returns
Section titled “Returns”string
staticof<TEvent>(kind):EventKey<TEvent>
Defined in: src/EventKey.ts:77
The parameter is KindOf<TEvent> rather than the free-form string that
ServiceKey.of takes, because unlike a service id the kind is a field of
the event type — so the relationship is checkable, and a mistyped kind
fails here instead of at run time by never matching anything. The
constructor keeps string as the raw door for a kind computed at run time.
Type Parameters
Section titled “Type Parameters”TEvent
Section titled “TEvent”TEvent extends object
Parameters
Section titled “Parameters”KindOf<TEvent>
Returns
Section titled “Returns”EventKey<TEvent>
