Strongly typed 0-dependency TypeScript EventTarget module.
npm i typed-events-target
import { TypedEvent, TypedEventTarget } from "typed-events-target";
deno add jsr:@von/typed-event-target
import { TypedEvent, TypedEventTarget } from "@von/typed-event-target";
type FooEvent = TypedEvent<"foo", string>;
type BarEvent = TypedEvent<"bar", number>;
class ExampleTarget extends TypedEventTarget<FooEvent | BarEvent> {
public emit(): void {
this.dispatchEvent("foo", "value");
this.dispatchEvent("bar", 42);
}
}
const target = new ExampleTarget();
target.addEventListener("foo", (evt) => console.log(evt.detail));
target.addEventListener("bar", (evt) => console.log(evt.detail));
target.emit();
Copyright © 2026 Violation.
This project is licensed under the terms of the GPL-3.0 licence.