1.0.1
Strictly typed EventTarget for Deno and the Browser
Repository
Current version released
4 years ago
Versions
Usage
import { TypedCustomEvent, TypedEventTarget } from 'https://deno.land/x/typed_event_target@1.0.1/mod.ts'
type Events = {
Hi: string
Hello: boolean
}
const emitter = new TypedEventTarget<Events>()
emitter.addEventListener("Hi", (value) => {
console.log(value.detail) // "Hello"
})
emitter.dispatchEvent(new TypedCustomEvent("Hi", { detail: "Hello" }))
API
Same as non-strict EventTarget, however a parameter must be passed to TypedCustomEvent
.