Skip to content

Is it possible to make EventTarget a generic interface? #49770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
masx200 opened this issue Jul 3, 2022 · 2 comments
Closed

Is it possible to make EventTarget a generic interface? #49770

masx200 opened this issue Jul 3, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@masx200
Copy link

masx200 commented Jul 3, 2022

lib Update Request

Is it possible to make EventTarget a generic interface?

Configuration Check

My compilation target is ESNEXT and my lib is the default.

Missing / Incorrect Definition

interface EventTarget<T extends Record<string, Event> = Record<string, Event>> {
    addEventListener<K extends keyof T>(type: K, listener: (this: EventTarget<T>, ev: T[K]) => any, options?: boolean | AddEventListenerOptions): void;
    addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
    dispatchEvent(event: T[keyof T]): boolean;
    dispatchEvent(event: Event): boolean;
    removeEventListener<K extends keyof T>(type: K, listener: (this: EventTarget<T>, ev: T[K]) => any, options?: boolean | EventListenerOptions): void;
    removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
}
declare const EventTarget: {
    new <T extends Record<string, Event> = Record<string, Event>>(): EventTarget<T>;
    prototype: EventTarget;
};
class TestTarget extends EventTarget<{
    complete: Event & {
        id: number;
    };
    message: MessageEvent;
}> {
constructor() {
        super()
    }
}

Sample Code

Documentation Link

@MartinJohns
Copy link
Contributor

Duplicate of #43477.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 5, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants