Skip to content

TypeScript type definitions for Event and EventTarget #1151

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

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

harmony7
Copy link
Member

Adding type declarations for Event and EventTarget

So now you can do this:

  const eventTargetTest = new Promise<string>(resolve => {

    class FooEvent extends Event {
      constructor(value: string) {
        super('foo');
        this.value = value;
      }
      readonly value: string;
    }

    const eventTarget = new EventTarget();
    eventTarget.addEventListener('foo', (event) => {
      resolve((event as FooEvent).value);
    });

    setTimeout(() => {

      eventTarget.dispatchEvent(new FooEvent('event-target-test'));

    }, 1000);

  });
  const eventTargetTestValue = await eventTargetTest;

@harmony7 harmony7 requested a review from guybedford March 13, 2025 07:03
@guybedford guybedford merged commit eb1ab0d into main Mar 13, 2025
23 of 28 checks passed
@guybedford guybedford deleted the kats/types-event-eventtarget branch March 13, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants