Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@types/events
Advanced tools
TypeScript definitions for 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.
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!');
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.
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.
npm install --save @types/events
This package contains type definitions for events (https://github.com/Gozala/events).
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[];
}
These definitions were written by Yasunori Ohoka, and Shenwei Wang.
FAQs
TypeScript definitions for events
We found that @types/events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.