tiny-typed-emitter icon indicating copy to clipboard operation
tiny-typed-emitter copied to clipboard

Provide also raw interface definition instead of just class

Open Granjow opened this issue 3 years ago • 0 comments

First, thanks for this helpful package @binier ! I used to manually declare onX(…) events to enforce typed events until I found it.

One thing I miss is a plain interface definition which I can inherit.


export interface ITypedEmitter<L extends ListenerSignature<L> = DefaultListener> {
    addListener<U extends keyof L>( event: U, listener: L[U] ): this;
    prependListener<U extends keyof L>( event: U, listener: L[U] ): this;
    // etc.
}

export interface MyInterfaceWithEvents extends ITypedEmitter<MyEvents> {
    // …
}

so users of the interface can also rely on typed events, not only users of the instance.

Granjow avatar Mar 19 '22 17:03 Granjow