# eventemitter-ts

> Typed EventEmitter classes for use with TypeScript

Latest version **0.0.4** (published 2018-06-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install eventemitter-ts
pnpm add eventemitter-ts
yarn add eventemitter-ts
bun add eventemitter-ts
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2018-06-25 |
| First published | 2018-05-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kevin Snyder |
| Maintainers | kevinsnydercodes |

## Links

- npm: https://www.npmjs.com/package/eventemitter-ts
- Repository: https://github.com/KevinSnyderCodes/eventemitter-ts
- Homepage: https://github.com/KevinSnyderCodes/eventemitter-ts#readme
- Issues: https://github.com/KevinSnyderCodes/eventemitter-ts/issues
- npm.io page: https://npm.io/package/eventemitter-ts

## Recent versions

- 0.0.4 (latest) — 2018-06-25
- 0.0.3 — 2018-06-25
- 0.0.2 — 2018-06-03
- 0.0.1 — 2018-05-29

## README

# eventemitter-ts

Typed `EventEmitter` classes for use with TypeScript.

## Installation

```sh
npm install eventemitter-ts
```

## Usage

All classes use the same interface as Node's built-in `EventEmitter`, but with generics for strict event types.

### `TypedEventEmitter`

```ts
import { TypedEventEmitter } from 'eventemitter-ts';

interface Events {
    'foo': number;
    'bar': string;
}

const ee = new TypedEventEmitter<Events>();

ee.on('foo', (arg: number) => {}); // OK
ee.on('bar', (arg: string) => {}); // OK
ee.on('baz', (arg: number) => {}); // Error! 'baz' is not a valid event
ee.on('foo', (arg: string) => {}); // Error! 'foo' event does not emit argument of type string
```

### `ProtectedEventEmitter`

```ts
import { ProtectedEventEmitter } from 'eventemitter-ts';

interface Events {
    'foo': number;
    'bar': string;
}

/**
 * Emits 'foo' event once every second.
 */
class MyEventEmitter extends ProtectedEventEmitter<Events> {
    constructor() {
        super();
        setInterval(() => {
            this.protectedEmit('foo', 123);
        }, 1000);
    }
}

const ee = new MyEventEmitter();
ee.on('foo', (arg: number) => {}); // OK
ee.emit('foo', 123); // NOP -- doesn't do anything, always returns false
```

---
_Source: https://npm.io/package/eventemitter-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
