TypedEmitter

The typed surface of the emitter. Class representing an event emitter described by a map, where an unknown event name is a compile error and a listener's parameters are inferred.

Signature

export interface TypedEmitter<T extends EventMap<T>>

JSDoc

Examples

interface MyEvents {
	ready: [at: number];
}

class MyThing extends TypedEmitter<MyEvents> {}

const thing = new MyThing();

thing.on("ready", (at) => console.log(at)); // `at` is a number
thing.emit("ready", Date.now());
@descriptionEvery method is listed on purpose: any left out keeps resolving to the inherited signature, which takes any name and gives the listener `any` arguments.@descriptionNode's emitter is the runtime, untouched: the class body is empty and the merged interface only describes it. The interface merges instead of the methods being `declare` fields, which would type them as properties and break a subclass overriding `on` with method syntax.@abstract@classTypedEmitter

Methods

emit<K extends EventKey<T>>(event: K, ...args: T[K]): boolean;