0.1.0 • Published 2 years ago
strict-event-target v0.1.0
strict-event-target
Strictly typed definitions for
EventTarget
Only used for type-checking; compiles to no code.
Install
npm install strict-event-target
Usage
import type StrictEventTarget from 'strict-event-target';
const target = new (EventTarget as typeof StrictEventTarget<{
foo: string; // Event with data
}, [
'bar', // Event without data
]>);
target.dispatchEvent(new CustomEvent('foo', {detail: 'The'}));
target.dispatchEvent(new Event('bar'));
import type StrictEventTarget from 'strict-event-target';
class Foo extends (EventTarget as typeof StrictEventTarget<{
foo: string; // Event with data
}, [
'bar', // Event without data
]>) {}
API
StrictEventTarget<EventsWithData?, EventsWithoutData?>
EventsWithData
Type: Record<string, unknown>
\
Default: {}
Events that will be created with CustomEvent
, thus being able to contain custom data.
EventsWithoutData
Type: string[]
\
Default: []
Events that will be created with Event
.
0.1.0
2 years ago