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

typed-emitter

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-emitter - npm Package Compare versions

Comparing version 1.5.0-from-event to 2.0.0

28

index.d.ts

@@ -1,4 +0,4 @@

export type Arguments<T> = [T] extends [(...args: infer U) => any]
? U
: [T] extends [void] ? [] : [T]
type EventMap = {
[key: string]: (...args: any[]) => void
}

@@ -10,16 +10,14 @@ /**

*
* ```typescript
* interface MyEvents {
* error: (error: Error) => void
* message: (from: string, content: string) => void
* error: (error: Error) => void;
* message: (from: string, content: string) => void;
* }
*
* const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>
* const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>;
*
* myEmitter.on("message", (from, content) => {
* // ...
* })
*
* myEmitter.emit("error", "x") // <- Will catch this type error
* myEmitter.emit("error", "x") // <- Will catch this type error;
* ```
*/
interface TypedEventEmitter<Events> {
interface TypedEventEmitter<Events extends EventMap> {
addListener<E extends keyof Events> (event: E, listener: Events[E]): this

@@ -35,7 +33,7 @@ on<E extends keyof Events> (event: E, listener: Events[E]): this

emit<E extends keyof Events> (event: E, ...args: Arguments<Events[E]>): boolean
emit<E extends keyof Events> (event: E, ...args: Parameters<Events[E]>): boolean
// The sloppy `eventNames()` return type is to mitigate type incompatibilities - see #5
eventNames (): (keyof Events | string | symbol)[]
rawListeners<E extends keyof Events> (event: E): Function[]
listeners<E extends keyof Events> (event: E): Function[]
rawListeners<E extends keyof Events> (event: E): Events[E][]
listeners<E extends keyof Events> (event: E): Events[E][]
listenerCount<E extends keyof Events> (event: E): number

@@ -42,0 +40,0 @@

{
"name": "typed-emitter",
"version": "1.5.0-from-event",
"version": "2.0.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Strictly typed event emitter interface for TypeScript 3.",

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