Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Collector): better types for events #6058

Merged
merged 2 commits into from Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 mc: MessageCollector;
mc.on('collect', (...args) => {
vaporoxx marked this conversation as resolved.
Show resolved Hide resolved
assertType<[Message]>(args);
});

declare const rc: ReactionCollector;
rc.on('dispose', (...args) => {
vaporoxx marked this conversation as resolved.
Show resolved Hide resolved
assertType<[MessageReaction, User]>(args);
});