Skip to content

Commit

Permalink
feat(Collector): better types for events (#6058)
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
  • Loading branch information
vaporoxx and kyranet committed Jul 5, 2021
1 parent 4c0426c commit c0a814f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions typings/index.d.ts
Expand Up @@ -391,10 +391,10 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
public abstract collect(...args: unknown[]): K | null | Promise<K | null>;
public abstract dispose(...args: unknown[]): K | null;

public on(event: 'collect' | 'dispose', listener: (...args: unknown[]) => Awaited<void>): this;
public on(event: 'collect' | 'dispose', listener: (...args: [V, ...F]) => Awaited<void>): this;
public on(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;

public once(event: 'collect' | 'dispose', listener: (...args: unknown[]) => Awaited<void>): this;
public once(event: 'collect' | 'dispose', listener: (...args: [V, ...F]) => Awaited<void>): this;
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;
}

Expand Down
14 changes: 14 additions & 0 deletions typings/index.ts
Expand Up @@ -8,11 +8,14 @@ import {
MessageActionRow,
MessageAttachment,
MessageButton,
MessageCollector,
MessageEmbed,
MessageReaction,
NewsChannel,
Options,
PartialTextBasedChannelFields,
Permissions,
ReactionCollector,
Serialized,
ShardClientUtil,
ShardingManager,
Expand Down Expand Up @@ -489,3 +492,14 @@ notPropertyOf(user, 'lastMessage');
notPropertyOf(user, 'lastMessageId');
notPropertyOf(guildMember, 'lastMessage');
notPropertyOf(guildMember, 'lastMessageId');

// Test collector event parameters
declare const messageCollector: MessageCollector;
messageCollector.on('collect', (...args) => {
assertType<[Message]>(args);
});

declare const reactionCollector: ReactionCollector;
reactionCollector.on('dispose', (...args) => {
assertType<[MessageReaction, User]>(args);
});

0 comments on commit c0a814f

Please sign in to comment.