PokéRogue
    Preparing search index...

    Interface TypedEventTarget<K, R>

    Interface restricting the events emitted by an EventTarget to a certain kind of Event, discriminated by their type properties.

    interface TypedEventTarget<K extends string, R extends Record<K, Event> = never> {
        addEventListener<
            EvtType extends string,
            T extends TypedEventTarget<K, R>,
        >(
            type: EvtType,
            callback: (this: T, evt: R[EvtType]) => void,
            options?: boolean | AddEventListenerOptions,
        ): void;
        dispatchEvent(event: R[K]): boolean;
        removeEventListener<
            EvtType extends string,
            T extends TypedEventTarget<K, R>,
        >(
            type: EvtType,
            callback: (this: T, evt: R[EvtType]) => void,
            options?: boolean | AddEventListenerOptions,
        ): void;
    }

    Type Parameters

    • K extends string

      A union of string literal types representing the allowed event names; only required to allow R to hold a subset of string keys and avoid index signature errors

    • R extends Record<K, Event> = never

      An object type matching event names in K to their corresponding Event subclasses.

    Hierarchy

    Index

    Methods

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      • event: R[K]

      Returns boolean