npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

event-emitter-typesafe

v0.1.3

Published

Simple event emitter working well with typescript

Downloads

26

Readme

event-emitter-typesafe

This package is meant to give you an easy to use way of defining an event emitter which is typesafe. Those definitions can be either applied by mixin or by extension of the EventEmitter class.

In either way those classes offer the three main methods add, remove and dispatch and several alias. The API documentation is available at: https://feirell.github.io/event-emitter-typesafe/.

usage

extending

The easiest way is to just extend the provided EventEmitter.

import {EventEmitter} from "event-emitter-typesafe";

// define all available events by their name and their structure
interface ExampleEvents {
    'example-a': { data: number },
    'example-b': { data: number },
    'example-c': { data: number },
    'example-d': { data: number }
}

// your class you want to extend to a event emitter
class Example extends EventEmitter<ExampleEvents> {
}

const e = new Example();

// add, remove and emit have their correct typings attached
e.once('example-c', () => console.log('example c was emitted'));
e.addEventListener('example-c', (ev) => console.log(ev.data));

// the first and the second listener will be called
e.emit('example-c', {data: 12});

// only the second listener will be called since the other one detached itself
// dispatch is just an alias for emit
e.dispatch('example-c', {data: 42});

e.on('example-a', () => { });

You can find this in examples\example-extending.ts

mixin

You can also use the second option which leverages TypeScript mixins which allow you to provide the functionality off the EventEmitter without extending it. This can be useful if you already are extending another class. Mixins results in pretty much the same type situation as you would have with extension.

import {EventEmitterInt, makeEventEmitter} from "event-emitter-typesafe";

class SomeOtherClass {}

// your class you want to extend to a event emitter but which also extends another class
class Example extends SomeOtherClass {}

// define all available events by their name and their structure
interface ExampleEvents {
    'example-a': { data: number },
    'example-b': { data: number },
    'example-c': { data: number },
    'example-d': { data: number }
}

// use a mixin to extend the type definition of the Example class
// typescript will add the event definitions to this class type definition
interface Example extends EventEmitterInt<ExampleEvents> {}

// actually add the implementation to the Example prototype
makeEventEmitter(Example);

// usage is transparent
const e = new Example();

// add, remove and emit have their correct typings attached
e.addEventListener('example-c', (ev) => console.log(ev.data));
e.dispatch('example-c', {data: 12});

You can find this in examples\example-mixin.ts

standalone

You could always just create an instance of the EventEmitter instead of extending it.

similar

The package @servie/events is quite similar but does not provide a mixin option and some of the alias.