typed-event-target
Version:
EventTarget in the browser but with strong event typing.
22 lines (21 loc) • 492 B
JavaScript
/**
* Define an `Event` sub-class with a type tied to its event type string.
*
* @category Events
* @example
*
* ```ts
* import {defineTypedEvent} from 'typed-event-target';
*
* defineTypedEvent('event-type-string');
* ```
*/
export function defineTypedEvent(type) {
const TypedEventConstructor = class extends Event {
static type = type;
constructor(eventInitDict) {
super(type, eventInitDict);
}
};
return TypedEventConstructor;
}