1.0.1 • Published 4 months ago
com.hydroper.typedeventtarget v1.0.1
Typed event target
Easily define event types for an EventTarget
, crediting to this article.
Getting started
The following program defines play
and stop
events.
import { TypedEventTarget } from "com.hydroper.typedeventtarget";
class MediaPlayer extends (EventTarget as TypedEventTarget<{
play: CustomEvent<MediaPlayerEvent>;
stop: CustomEvent<MediaPlayerEvent>;
}>) {}
Note that event types must implement the
Event
interface, thus in the previous programCustomEvent
is used; if there was no data, it could have just beenEvent
itself.