/** * Base type that a CustomEventEmitter may receive as a generic type * to discriminate possible events. */ type CustomEventMap = Record; /** * Extracts the keys from a CustomEventMap so they can be used as event types. * For example, for the CustomEventMap * ```ts * { * "longpress": {position: number[]} * "shortpress": {position: number[]} * } * ``` * This type will infer `"longpress" | "shortpress"`. */ type CustomEventKey = string & keyof EvtMap; /** * Any function or object that can be used to listen to an event. */ type CustomEventListenerOrEventListenerObject = | { handleEvent(event: CustomEvent): void } | ((event: CustomEvent) => void); /** * An event emitter that can be mixed in to other objects. */ interface CustomEventEmitter { addEventListener>( eventName: K, fn: CustomEventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean ): void; removeEventListener>( eventName: K, fn: CustomEventListenerOrEventListenerObject, options?: EventListenerOptions | boolean ): void; dispatchEvent>( eventName: K, detail: EvtMap[K] ): void; signal: AbortSignal; abort: AbortController["abort"]; }