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

@types/node

Package Overview
Dependencies
Maintainers
1
Versions
1954
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/node - npm Package Compare versions

Comparing version 22.8.4 to 22.8.5

213

node/events.d.ts

@@ -37,2 +37,3 @@ /**

*/
declare module "events" {

@@ -103,19 +104,23 @@ import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";

}
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {}
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
type DefaultEventMap = [never];
type AnyRest = [...args: any[]];
type Args<K, T> = T extends DefaultEventMap ? AnyRest : (
K extends keyof T ? T[K] : never
);
type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T;
type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T;
type Listener<K, T, F> = T extends DefaultEventMap ? F : (
K extends keyof T ? (
T[K] extends unknown[] ? (...args: T[K]) => void : never
)
: never
);
type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>;
type Listener2<K, T> = Listener<K, T, Function>;
interface EventEmitter<Events extends EventMap<Events> = {}> extends NodeJS.EventEmitter<Events> {}
type EventMap<Events> = Record<keyof Events, unknown[]>;
type Args<Events extends EventMap<Events>, EventName> = EventName extends keyof Events ? (
| Events[EventName]
| (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
? EventEmitter.EventEmitterBuiltInEventMap[EventName]
: never)
)
: (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
? EventEmitter.EventEmitterBuiltInEventMap[EventName]
: any[]);
type EventNames<Events extends EventMap<Events>> = {} extends Events ? (string | symbol)
: (keyof Events | keyof EventEmitter.EventEmitterBuiltInEventMap);
type Listener<Events extends EventMap<Events>, EventName> = EventName extends keyof Events ?
| ((...args: Events[EventName]) => void)
| (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
? (...args: EventEmitter.EventEmitterBuiltInEventMap[EventName]) => void
: never)
: (EventName extends keyof EventEmitter.EventEmitterBuiltInEventMap
? (...args: EventEmitter.EventEmitterBuiltInEventMap[EventName]) => void
: (...args: any[]) => void);

@@ -135,7 +140,17 @@ /**

*/
class EventEmitter<T extends EventMap<T> = DefaultEventMap> {
class EventEmitter<Events extends EventMap<Events> = {}> {
constructor(options?: EventEmitterOptions);
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
// This "property" is used to brand a specific instance of the EventEmitter class with its Event map, which is needed
// in order to infer the map if we have a chain like `class A extends EventEmitter<{}>` (or many levels deep)
// It is also marked as possibly undefined in order to allow something like `const t: NodeJS.EventEmitter<{}> = { <insert implementation here> };`
readonly #internalTypeOnlyBrand?: Events;
[EventEmitter.captureRejectionSymbol]?<EventName extends EventNames<Events>>(
error: Error,
event: EventName,
...args: Args<Events, EventName>
): void;
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string | symbol, ...args: any[]): void;
/**

@@ -220,2 +235,7 @@ * Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given

*/
static once<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
emitter: EventEmitter<Events>,
eventName: EventName,
options?: StaticEventEmitterOptions,
): Promise<Args<Events, EventName>>;
static once(

@@ -307,2 +327,7 @@ emitter: NodeJS.EventEmitter,

*/
static on<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
emitter: EventEmitter<Events>,
eventName: EventName,
options?: StaticEventEmitterIteratorOptions,
): NodeJS.AsyncIterator<Args<Events, EventName>>;
static on(

@@ -335,2 +360,23 @@ emitter: NodeJS.EventEmitter,

*/
static listenerCount<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
emitter: EventEmitter<Events>,
eventName: EventName,
): number;
/**
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
*
* ```js
* import { EventEmitter, listenerCount } from 'node:events';
*
* const myEmitter = new EventEmitter();
* myEmitter.on('event', () => {});
* myEmitter.on('event', () => {});
* console.log(listenerCount(myEmitter, 'event'));
* // Prints: 2
* ```
* @since v0.9.12
* @deprecated Since v3.2.0 - Use `listenerCount` instead.
* @param emitter The emitter to query
* @param eventName The event name
*/
static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;

@@ -364,3 +410,10 @@ /**

*/
static getEventListeners(emitter: EventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
static getEventListeners<Events extends EventMap<Events>, EventName extends EventNames<Events>>(
emitter: EventEmitter<Events>,
name: EventName,
): Array<Listener<Events, EventName>>;
static getEventListeners(
emitter: EventTarget | NodeJS.EventEmitter,
name: string | symbol,
): Function[];
/**

@@ -595,7 +648,21 @@ * Returns the currently set max amount of listeners.

}
export interface EventEmitterBuiltInEventMap {
newListener: [eventName: string | symbol, listener: Function];
removeListener: [eventName: string | symbol, listener: Function];
}
}
global {
namespace NodeJS {
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> {
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
interface EventEmitter<Events extends EventMap<Events> = {}> {
[EventEmitter.captureRejectionSymbol]?<EventName extends EventNames<Events>>(
error: Error,
event: EventName,
...args: Args<Events, EventName>
): void;
[EventEmitter.captureRejectionSymbol]?<EventName extends string | symbol>(
error: Error,
event: EventName,
...args: Args<Events, EventName>
): void;
/**

@@ -605,3 +672,10 @@ * Alias for `emitter.on(eventName, listener)`.

*/
addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
addListener<EventName extends EventNames<Events>>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
addListener<EventName extends string | symbol>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
/**

@@ -638,3 +712,10 @@ * Adds the `listener` function to the end of the listeners array for the event

*/
on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
on<EventName extends EventNames<Events>>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
on<EventName extends string | symbol>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
/**

@@ -669,3 +750,10 @@ * Adds a **one-time** `listener` function for the event named `eventName`. The

*/
once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
once<EventName extends EventNames<Events>>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
once<EventName extends string | symbol>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
/**

@@ -753,3 +841,10 @@ * Removes the specified `listener` from the listener array for the event named `eventName`.

*/
removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
removeListener<EventName extends EventNames<Events>>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
removeListener<EventName extends string | symbol>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
/**

@@ -759,3 +854,10 @@ * Alias for `emitter.removeListener()`.

*/
off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
off<EventName extends EventNames<Events>>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
off<EventName extends string | symbol>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
/**

@@ -771,3 +873,6 @@ * Removes all listeners, or those of the specified `eventName`.

*/
removeAllListeners(eventName?: Key<unknown, T>): this;
/* eslint-disable @definitelytyped/no-unnecessary-generics */
removeAllListeners<EventName extends EventNames<Events>>(eventName: EventName): this;
removeAllListeners<EventName extends string | symbol>(eventName?: EventName): this;
/* eslint-enable @definitelytyped/no-unnecessary-generics */
/**

@@ -801,3 +906,8 @@ * By default `EventEmitter`s will print a warning if more than `10` listeners are

*/
listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
listeners<EventName extends EventNames<Events>>(
eventName: EventName,
): Array<Listener<Events, EventName>>;
listeners<EventName extends string | symbol>(
eventName: EventName,
): Array<Listener<Events, EventName>>;
/**

@@ -833,3 +943,8 @@ * Returns a copy of the array of listeners for the event named `eventName`,

*/
rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
rawListeners<EventName extends EventNames<Events>>(
eventName: EventName,
): Array<Listener<Events, EventName>>;
rawListeners<EventName extends string | symbol>(
eventName: EventName,
): Array<Listener<Events, EventName>>;
/**

@@ -875,3 +990,10 @@ * Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments

*/
emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean;
emit<EventName extends EventNames<Events>>(
eventName: EventName,
...args: Args<Events, EventName>
): boolean;
emit<EventName extends string | symbol>(
eventName: EventName,
...args: Args<Events, EventName>
): boolean;
/**

@@ -885,3 +1007,10 @@ * Returns the number of listeners listening for the event named `eventName`.

*/
listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number;
listenerCount<EventName extends EventNames<Events>>(
eventName: EventName,
listener?: Listener<Events, EventName>,
): number;
listenerCount<EventName extends string | symbol>(
eventName: EventName,
listener?: Listener<Events, EventName>,
): number;
/**

@@ -904,3 +1033,10 @@ * Adds the `listener` function to the _beginning_ of the listeners array for the

*/
prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
prependListener<EventName extends EventNames<Events>>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
prependListener<EventName extends string | symbol>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
/**

@@ -921,3 +1057,10 @@ * Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this

*/
prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
prependOnceListener<EventName extends EventNames<Events>>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
prependOnceListener<EventName extends string | symbol>(
eventName: EventName,
listener: Listener<Events, EventName>,
): this;
/**

@@ -942,3 +1085,3 @@ * Returns an array listing the events for which the emitter has registered

*/
eventNames(): Array<(string | symbol) & Key2<unknown, T>>;
eventNames(): Array<(string | symbol)> & Array<EventNames<Events>>;
}

@@ -945,0 +1088,0 @@ }

4

node/package.json
{
"name": "@types/node",
"version": "22.8.4",
"version": "22.8.5",
"description": "TypeScript definitions for node",

@@ -223,4 +223,4 @@ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",

"peerDependencies": {},
"typesPublisherContentHash": "b5e95f7873a1811a61b3409c809ee30655d0268d76d767dbe9efc27cb421459f",
"typesPublisherContentHash": "7165aa45b80abb5ff9333ec6ca387d477f843670bbad567424c59b148b46fa23",
"typeScriptVersion": "4.8"
}

@@ -11,3 +11,3 @@ # Installation

### Additional Details
* Last updated: Tue, 29 Oct 2024 17:02:26 GMT
* Last updated: Thu, 31 Oct 2024 05:35:24 GMT
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)

@@ -14,0 +14,0 @@

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