import { TypedCustomEvent, TypedEventTarget } from 'https://deno.land/x/[email protected]/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" }))
Same as non-strict EventTarget, however a parameter must be passed to TypedCustomEvent
.