# tsee

> Typed EventEmitter implemented with typed args

Latest version **1.3.4** (published 2023-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install tsee
pnpm add tsee
yarn add tsee
bun add tsee
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2023-04-09 |
| First published | 2019-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | morglod |
| Maintainers | morglod |
| Keywords | types, ts, typescript, events, eventemitter, event-listener, eventlistener, listener, emit |

## Links

- npm: https://www.npmjs.com/package/tsee
- Repository: https://github.com/Morglod/ts-event-emitter
- Homepage: https://github.com/Morglod/ts-event-emitter#readme
- Issues: https://github.com/Morglod/ts-event-emitter/issues
- npm.io page: https://npm.io/package/tsee

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^12.7.2

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.3.4 (latest) — 2023-04-09
- 1.3.3 — 2023-02-22
- 1.3.2 — 2020-11-04
- 1.3.1 — 2020-10-20
- 1.3.0 — 2019-09-02
- 1.2.2 — 2019-08-29
- 1.2.1 — 2019-06-26
- 1.2.0 — 2019-06-24

## README

[![NPM Version](https://badge.fury.io/js/tsee.svg?style=flat)](https://www.npmjs.com/package/tsee) [![NPM Downloads](https://img.shields.io/npm/dw/tsee)](https://www.npmjs.com/package/tsee)

# tsee

Typed EventEmitter implemented with typed args, based on nodejs EventEmitter.  
Fully implements `NodeJS.EventEmitter` type, provides interface & proxy class.

[Check 'tseep'! Same api but world fastest event emitter](https://github.com/Morglod/tseep)

## Install & use

```
npm i tsee
```

Simple usage:

```ts
import { EventEmitter } from "tsee";

const events = new EventEmitter<{
    foo: (a: number, b: string) => void;
}>();

// foo's arguments is fully type checked
events.emit("foo", 123, "hello world");
```

Cast any other compatible to `NodeJS.EventEmitter` to typed:

```ts
import { asTypedEventEmitter } from "tsee";

const typedEmitter = asTypedEventEmitter<{
    foo: (a: number, b: string) => void;
    boo: (a: number, b: string) => void;
}>(myEmitter);

typedEmitter.emit("foo", 123, "hello world");
```

## Advenced usage for non default event emitters

If you use custom EventEmitter implementation, you can simply cast it to `tsee.IEventEmitter` interface:

```ts
import { CustomEventEmitter } from 'my-event-emitter';
import * as tsee from 'tsee';

// Simple type case
const typed = new CustomEventEmitter() as any as tsee.IEventEmitter<{ ... }>;

// Functional cast with `NodeJS.EventEmitter` type constraints
const typed = asTypedEventEmitter<{ ... }>(new CustomEventEmitter());

```

`tsee.EventEmitter` class is implemented EventEmitter from 'events' package.

## Api

`EventEmitter<T>` where `T` extends `{ [eventName]: Call signature }`.

`EventEmitter.emit`'s args is fully typed based on events map.

For `foo` event in example above, signature is: `emit(eventName: 'foo', a: number, b: string)`.

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