Skip to content

Latest commit

 

History

History
55 lines (36 loc) · 1.19 KB

readme.md

File metadata and controls

55 lines (36 loc) · 1.19 KB

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.