Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsee

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsee

Typed EventEmitter implemented with tsargs

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.3K
decreased by-15.78%
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version

tsee

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

Install & use

npm i tsee

Simple usage:

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:

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:

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).

Keywords

FAQs

Package last updated on 02 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc