strict-event-target
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i strict-event-target

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

5.08 kB

Total Files

4

Last publish

Collaborators

  • richienb