diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 2acb6c38df15..7a7231c497b3 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -244,20 +244,6 @@ import { RawWidgetMemberData, } from './rawDataTypes.js'; -declare module 'node:events' { - class EventEmitter { - // Add type overloads for client events. - public static once( - eventEmitter: Emitter, - eventName: Emitter extends Client ? Event : string, - ): Promise; - public static on( - eventEmitter: Emitter, - eventName: Emitter extends Client ? Events : string, - ): AsyncIterableIterator; - } -} - //#region Classes export class Activity { @@ -999,6 +985,18 @@ export class Client extends BaseClient { // This a technique used to brand the ready state. Or else we'll get `never` errors on typeguard checks. private readonly _ready: Ready; + // Override inherited static EventEmitter methods, with added type checks for Client events. + public static once( + eventEmitter: Emitter, + eventName: Emitter extends Client ? Event : string | symbol, + options?: { signal?: AbortSignal | undefined }, + ): Promise; + public static on( + eventEmitter: Emitter, + eventName: Emitter extends Client ? Event : string | symbol, + options?: { signal?: AbortSignal | undefined }, + ): AsyncIterableIterator; + public application: If; public channels: ChannelManager; public get emojis(): BaseGuildEmojiManager; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index a3b0e7be102f..f2db5f9a6f58 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -1297,6 +1297,10 @@ client.on('guildCreate', async g => { ); }); +// EventEmitter static method overrides +expectType]>>(Client.once(client, 'ready')); +expectType]>>(Client.on(client, 'ready')); + client.login('absolutely-valid-token'); declare const loggedInClient: Client;