diff --git a/src/@types/typed-event-target.ts b/src/@types/typed-event-target.ts new file mode 100644 index 00000000000..2c38a6812d6 --- /dev/null +++ b/src/@types/typed-event-target.ts @@ -0,0 +1,17 @@ +/** + * Interface restricting the events emitted by an {@linkcode EventTarget} to a certain kind of {@linkcode Event}. + * @typeParam T - The type to restrict the interface's access; must extend from {@linkcode Event} + */ +export interface TypedEventTarget extends EventTarget { + dispatchEvent(event: T): boolean; + addEventListener( + event: T["type"], + callback: EventListenerOrEventListenerObject | null, + options?: AddEventListenerOptions | boolean, + ): void; + removeEventListener( + type: T["type"], + callback: EventListenerOrEventListenerObject | null, + options?: EventListenerOptions | boolean, + ): void; +}