From abb7e259065073f799ac73a8d9111776f96cba9d Mon Sep 17 00:00:00 2001 From: almeidx Date: Sun, 19 Jan 2025 13:24:30 +0000 Subject: [PATCH] fix: requested changes --- packages/discord.js/typings/index.d.ts | 36 +++++++++++++-------- packages/discord.js/typings/index.test-d.ts | 21 ++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 37242651c1d9..7bc046078d0a 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -959,7 +959,7 @@ export type If = Value ex ? FalseResult : TrueResult | FalseResult; -export class Client extends BaseClient { +export class Client extends BaseClient { public constructor(options: ClientOptions); private actions: unknown; private expectedGuilds: Set; @@ -1098,9 +1098,12 @@ export interface CollectorEventTypes end: [collected: ReadonlyCollection, reason: string]; } -export abstract class Collector extends AsyncEventEmitter< - CollectorEventTypes -> { +export abstract class Collector< + Key, + Value, + Extras extends unknown[] = [], + EventTypes extends {} = CollectorEventTypes, +> extends AsyncEventEmitter { protected constructor(client: Client, options?: CollectorOptions<[Value, ...Extras]>); private _timeout: NodeJS.Timeout | null; private _idletimeout: NodeJS.Timeout | null; @@ -1965,11 +1968,7 @@ export class InteractionCallbackResource { public type: InteractionResponseType; } -export class InteractionCollector extends Collector< - Snowflake, - Interaction, - [Collection] -> { +export class InteractionCollector extends Collector { public constructor(client: Client, options?: InteractionCollectorOptions); private _handleMessageDeletion(message: Message): void; private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void; @@ -2710,7 +2709,16 @@ export class PollAnswer extends Base { public fetchVoters(options?: BaseFetchPollAnswerVotersOptions): Promise>; } -export class ReactionCollector extends Collector { +export interface ReactionCollectorEventTypes extends CollectorEventTypes { + remove: [reaction: MessageReaction, user: User]; +} + +export class ReactionCollector extends Collector< + Snowflake | string, + MessageReaction, + [User], + ReactionCollectorEventTypes +> { public constructor(message: Message, options?: ReactionCollectorOptions); private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void; private _handleGuildDeletion(guild: Guild): void; @@ -2986,11 +2994,11 @@ export class ShardClientUtil { public static shardIdForGuildId(guildId: Snowflake, shardCount: number): number; } -export interface ShardingManagerEvents { +export interface ShardingManagerEventTypes { shardCreate: [shard: Shard]; } -export class ShardingManager extends AsyncEventEmitter { +export class ShardingManager extends AsyncEventEmitter { public constructor(file: string, options?: ShardingManagerOptions); private _performOnShards(method: string, args: readonly unknown[]): Promise; private _performOnShards(method: string, args: readonly unknown[], shard: number): Promise; @@ -5071,7 +5079,7 @@ export type OmitPartialGroupDMChannel = channel: Exclude; }; -export interface ClientEvents { +export interface ClientEventTypes { applicationCommandPermissionsUpdate: [data: ApplicationCommandPermissionsUpdateData]; autoModerationActionExecution: [autoModerationActionExecution: AutoModerationActionExecution]; autoModerationRuleCreate: [autoModerationRule: AutoModerationRule]; @@ -6085,7 +6093,7 @@ export type CollectedInteraction = export interface InteractionCollectorOptions< Interaction extends CollectedInteraction, Cached extends CacheType = CacheType, -> extends CollectorOptions<[Interaction, Collection]> { +> extends CollectorOptions<[Interaction]> { channel?: TextBasedChannelResolvable; componentType?: ComponentType; guild?: GuildResolvable; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 3b40d874e024..f76dfab01ce7 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -473,6 +473,10 @@ client.on('messageCreate', async message => { expectAssignable>(channel.awaitMessageComponent({ componentType: ComponentType.Button })); expectAssignable>(buttonCollector); + buttonCollector.on('collect', (...args) => expectType<[ButtonInteraction]>(args)); + buttonCollector.on('dispose', (...args) => expectType<[ButtonInteraction]>(args)); + buttonCollector.on('end', (...args) => expectType<[ReadonlyCollection, string]>(args)); + // Verify that select menus interaction are inferred. const selectMenuCollector = message.createMessageComponentCollector({ componentType: ComponentType.StringSelect }); expectAssignable>( @@ -483,12 +487,24 @@ client.on('messageCreate', async message => { ); expectAssignable>(selectMenuCollector); + selectMenuCollector.on('collect', (...args) => expectType<[SelectMenuInteraction]>(args)); + selectMenuCollector.on('dispose', (...args) => expectType<[SelectMenuInteraction]>(args)); + selectMenuCollector.on('end', (...args) => + expectType<[ReadonlyCollection, string]>(args), + ); + // Verify that message component interactions are default collected types. const defaultCollector = message.createMessageComponentCollector(); expectAssignable>(message.awaitMessageComponent()); expectAssignable>(channel.awaitMessageComponent()); expectAssignable>(defaultCollector); + defaultCollector.on('collect', (...args) => expectType<[MessageComponentInteraction]>(args)); + defaultCollector.on('dispose', (...args) => expectType<[MessageComponentInteraction]>(args)); + defaultCollector.on('end', (...args) => + expectType<[ReadonlyCollection, string]>(args), + ); + // Verify that additional options don't affect default collector types. const semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 }); expectType>(semiDefaultCollector); @@ -1419,6 +1435,11 @@ reactionCollector.on('dispose', (...args) => { expectType<[MessageReaction, User]>(args); }); +reactionCollector.on('collect', (...args) => expectType<[MessageReaction, User]>(args)); +reactionCollector.on('dispose', (...args) => expectType<[MessageReaction, User]>(args)); +reactionCollector.on('remove', (...args) => expectType<[MessageReaction, User]>(args)); +reactionCollector.on('end', (...args) => expectType<[ReadonlyCollection, string]>(args)); + (async () => { for await (const value of reactionCollector) { expectType<[MessageReaction, User]>(value);