Skip to main content
The Deno 2 Release Candidate is here
Learn more
typed_event_target illustration

Typed Event Target

Strictly typed EventTarget for Deno and the Browser

build status language code size issues license version

View on deno.land




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.

Supporters

Stargazers repo roster for @KhushrajRathod/TypedEventTarget

Forkers repo roster for @KhushrajRathod/TypedEventTarget