What is @types/events?
The @types/events package provides TypeScript type definitions for the Node.js 'events' module, which is used for handling events in an application. This package does not contain functionality by itself but offers type annotations for TypeScript developers to ensure type safety and better development experience when working with event-driven programming in Node.js.
What are @types/events's main functionalities?
EventEmitter Type Definitions
Provides type definitions for creating and using an EventEmitter to handle custom events. The code sample demonstrates how to create an EventEmitter, subscribe to an event with a specific type of listener function, and emit an event.
import { EventEmitter } from 'events';
const emitter: EventEmitter = new EventEmitter();
emitter.on('event', (message: string) => {
console.log(`Received message: ${message}`);
});
emitter.emit('event', 'Hello World!');
Other packages similar to @types/events
eventemitter3
EventEmitter3 is a high-performance EventEmitter. It provides similar functionality to Node.js's native EventEmitter from which @types/events derives its types. EventEmitter3 is often chosen for its performance optimizations and is compatible with a broader range of environments, including those where native EventEmitters are not available.
wolfy87-eventemitter
This package is another alternative to the native EventEmitter, offering similar functionalities with additional features like namespaces, wildcards, and times to listen. It does not have built-in TypeScript support, unlike @types/events, but can be more flexible in complex event handling scenarios.
Installation
npm install --save @types/events
Summary
This package contains type definitions for events (https://github.com/Gozala/events).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/events.
export type Listener = (...args: any[]) => void;
export class EventEmitter {
static listenerCount(emitter: EventEmitter, type: string | number): number;
static defaultMaxListeners: number;
eventNames(): Array<string | number>;
setMaxListeners(n: number): this;
getMaxListeners(): number;
emit(type: string | number, ...args: any[]): boolean;
addListener(type: string | number, listener: Listener): this;
on(type: string | number, listener: Listener): this;
once(type: string | number, listener: Listener): this;
prependListener(type: string | number, listener: Listener): this;
prependOnceListener(type: string | number, listener: Listener): this;
removeListener(type: string | number, listener: Listener): this;
off(type: string | number, listener: Listener): this;
removeAllListeners(type?: string | number): this;
listeners(type: string | number): Listener[];
listenerCount(type: string | number): number;
rawListeners(type: string | number): Listener[];
}
Additional Details
- Last updated: Wed, 18 Oct 2023 01:17:34 GMT
- Dependencies: none
Credits
These definitions were written by Yasunori Ohoka, and Shenwei Wang.