@bsunderhus/event-target
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

EventTarget with EventMap typings

This project aims to reexport the global definition of EventTarget but adding new typings definitions that allow Event maps declarations.

Usage

Event maps is a simple type that can be passed to EventTarget constructor as a generic to better specify possible events that will be dispatched by a given EventTarget

type EventMapExample = {
  toggle: CustomEvent<boolean>;
  error: ErrorEvent;
};

const eventTarget = new EventTarget<EventMapExample>();

eventTarget.addEventListener("error", (e) => e /* ErrorEvent */);
eventTarget.addEventListener("toggle", (e) => e /* CustomEvent<boolean> */);
eventTarget.addEventListener("custom", (e) => e /* Event */);

Readme

Keywords

Package Sidebar

Install

npm i @bsunderhus/event-target

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

8.66 kB

Total Files

7

Last publish

Collaborators

  • bsunderhus