Skip to content

Strictly typed definitions for EventTarget

License

Notifications You must be signed in to change notification settings

Richienb/strict-event-target

Repository files navigation

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.

About

Strictly typed definitions for EventTarget

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published