Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eventemitter-strict

moonrailgun2.8kMIT1.0.1TypeScript support: included

A eventemitter with typescript full support

EventEmitter, EventEmitter2, EventEmitter3, Events, addEventListener, addListener, on, off, emit, emits, emitter, event, once, pubsub, pub/sub, publish, reactor, subscribe

readme

eventemitter-strict

A eventemitter with typescript full support

eventemitter-strict is a eventemitter with typescript full support. The module is API compatible with the EventEmitter that ships by default with Node.js.

Allow to type safe definition your eventemitter

Feature

  • typesafe
  • compatible with nodejs
  • simple but strong

Install

npm install eventemitter-strict

Usage

import { EventEmitter } from 'eventemitter-strict';

interface FooEventMap {
  eventA: () => void;
  eventB: (num: number) => void;
}

const ee = new EventEmitter<FooEventMap>();
ee.emit('eventA');
ee.emit('eventB', 1);
ee.emit('eventB', "Any"); // this will throw error in ts

or use with extends

import { EventEmitter } from 'eventemitter-strict';

interface FooEventMap {
  eventA: () => void;
  eventB: (num: number) => void;
}

class Foo extends EventEmitter<FooEventMap> {
  bar() {
    this.emit('eventA');
    this.emit('eventB', 1);
    this.emit('eventB', "Any"); // this will throw error in ts
  }
}

License

MIT