UNPKG

@snap/camera-kit

Version:
26 lines 1.5 kB
import type { EventOfType, TypedCustomEvent } from "./TypedCustomEvent"; export type TypedEventListener<Event extends TypedCustomEvent> = (evt: Event) => void; export interface TypedEventListenerOptions { once?: boolean; } /** * Extract the generic Events type (which must extend {@link TypedCustomEvent}) from a {@link TypedEventTarget} */ export type EventsFromTarget<Target extends TypedEventTarget> = Target extends TypedEventTarget<infer Events> ? Events : never; /** * This wrapper around EventTarget provides more descriptive type information. By using this class, calls to EventTarget * methods are correctly type checked to ensure only allowed event types are used, and that events and their type * strings are correctly associated. * * For example, when calling TypedEventTarget::addEventListener, the event passed to the callback will have the correct * type corresponding to the type of event for which the listener has been added. */ export declare class TypedEventTarget<Events extends TypedCustomEvent = TypedCustomEvent> { private readonly listeners; private readonly options; constructor(); addEventListener<K extends Events["type"]>(type: K, callback: TypedEventListener<EventOfType<K, Events>>, options?: TypedEventListenerOptions): void; dispatchEvent(event: Events): true; removeEventListener<K extends Events["type"]>(type: K, callback: TypedEventListener<EventOfType<K, Events>>): void; } //# sourceMappingURL=TypedEventTarget.d.ts.map