Skip to content

Commit

Permalink
fix: requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed Jan 19, 2025
1 parent 9ad40b7 commit abb7e25
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
36 changes: 22 additions & 14 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ export type If<Value extends boolean, TrueResult, FalseResult = null> = Value ex
? FalseResult
: TrueResult | FalseResult;

export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEvents> {
export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEventTypes> {
public constructor(options: ClientOptions);
private actions: unknown;
private expectedGuilds: Set<Snowflake>;
Expand Down Expand Up @@ -1098,9 +1098,12 @@ export interface CollectorEventTypes<Key, Value, Extras extends unknown[] = []>
end: [collected: ReadonlyCollection<Key, Value>, reason: string];
}

export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends AsyncEventEmitter<
CollectorEventTypes<Key, Value, Extras>
> {
export abstract class Collector<
Key,
Value,
Extras extends unknown[] = [],
EventTypes extends {} = CollectorEventTypes<Key, Value, Extras>,
> extends AsyncEventEmitter<EventTypes> {
protected constructor(client: Client<true>, options?: CollectorOptions<[Value, ...Extras]>);
private _timeout: NodeJS.Timeout | null;
private _idletimeout: NodeJS.Timeout | null;
Expand Down Expand Up @@ -1965,11 +1968,7 @@ export class InteractionCallbackResource {
public type: InteractionResponseType;
}

export class InteractionCollector<Interaction extends CollectedInteraction> extends Collector<
Snowflake,
Interaction,
[Collection<Snowflake, Interaction>]
> {
export class InteractionCollector<Interaction extends CollectedInteraction> extends Collector<Snowflake, Interaction> {
public constructor(client: Client<true>, options?: InteractionCollectorOptions<Interaction>);
private _handleMessageDeletion(message: Message): void;
private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;
Expand Down Expand Up @@ -2710,7 +2709,16 @@ export class PollAnswer extends Base {
public fetchVoters(options?: BaseFetchPollAnswerVotersOptions): Promise<Collection<Snowflake, User>>;
}

export class ReactionCollector extends Collector<Snowflake | string, MessageReaction, [User]> {
export interface ReactionCollectorEventTypes extends CollectorEventTypes<Snowflake | string, MessageReaction, [User]> {
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;
Expand Down Expand Up @@ -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<ShardingManagerEvents> {
export class ShardingManager extends AsyncEventEmitter<ShardingManagerEventTypes> {
public constructor(file: string, options?: ShardingManagerOptions);
private _performOnShards(method: string, args: readonly unknown[]): Promise<unknown[]>;
private _performOnShards(method: string, args: readonly unknown[], shard: number): Promise<unknown>;
Expand Down Expand Up @@ -5071,7 +5079,7 @@ export type OmitPartialGroupDMChannel<Structure extends { channel: Channel }> =
channel: Exclude<Structure['channel'], PartialGroupDMChannel>;
};

export interface ClientEvents {
export interface ClientEventTypes {
applicationCommandPermissionsUpdate: [data: ApplicationCommandPermissionsUpdateData];
autoModerationActionExecution: [autoModerationActionExecution: AutoModerationActionExecution];
autoModerationRuleCreate: [autoModerationRule: AutoModerationRule];
Expand Down Expand Up @@ -6085,7 +6093,7 @@ export type CollectedInteraction<Cached extends CacheType = CacheType> =
export interface InteractionCollectorOptions<
Interaction extends CollectedInteraction,
Cached extends CacheType = CacheType,
> extends CollectorOptions<[Interaction, Collection<Snowflake, Interaction>]> {
> extends CollectorOptions<[Interaction]> {
channel?: TextBasedChannelResolvable;
componentType?: ComponentType;
guild?: GuildResolvable;
Expand Down
21 changes: 21 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ client.on('messageCreate', async message => {
expectAssignable<Promise<ButtonInteraction>>(channel.awaitMessageComponent({ componentType: ComponentType.Button }));
expectAssignable<InteractionCollector<ButtonInteraction>>(buttonCollector);

buttonCollector.on('collect', (...args) => expectType<[ButtonInteraction]>(args));
buttonCollector.on('dispose', (...args) => expectType<[ButtonInteraction]>(args));
buttonCollector.on('end', (...args) => expectType<[ReadonlyCollection<Snowflake, ButtonInteraction>, string]>(args));

// Verify that select menus interaction are inferred.
const selectMenuCollector = message.createMessageComponentCollector({ componentType: ComponentType.StringSelect });
expectAssignable<Promise<StringSelectMenuInteraction>>(
Expand All @@ -483,12 +487,24 @@ client.on('messageCreate', async message => {
);
expectAssignable<InteractionCollector<StringSelectMenuInteraction>>(selectMenuCollector);

selectMenuCollector.on('collect', (...args) => expectType<[SelectMenuInteraction]>(args));
selectMenuCollector.on('dispose', (...args) => expectType<[SelectMenuInteraction]>(args));
selectMenuCollector.on('end', (...args) =>
expectType<[ReadonlyCollection<Snowflake, SelectMenuInteraction>, string]>(args),
);

// Verify that message component interactions are default collected types.
const defaultCollector = message.createMessageComponentCollector();
expectAssignable<Promise<MessageComponentInteraction>>(message.awaitMessageComponent());
expectAssignable<Promise<MessageComponentInteraction>>(channel.awaitMessageComponent());
expectAssignable<InteractionCollector<CollectedMessageInteraction>>(defaultCollector);

defaultCollector.on('collect', (...args) => expectType<[MessageComponentInteraction]>(args));
defaultCollector.on('dispose', (...args) => expectType<[MessageComponentInteraction]>(args));
defaultCollector.on('end', (...args) =>
expectType<[ReadonlyCollection<Snowflake, MessageComponentInteraction>, string]>(args),
);

// Verify that additional options don't affect default collector types.
const semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 });
expectType<InteractionCollector<CollectedMessageInteraction>>(semiDefaultCollector);
Expand Down Expand Up @@ -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, MessageReaction>, string]>(args));

(async () => {
for await (const value of reactionCollector) {
expectType<[MessageReaction, User]>(value);
Expand Down

0 comments on commit abb7e25

Please sign in to comment.