From c0a814fdb35cb1fa7418bb3bdd3cec0a8a130bf5 Mon Sep 17 00:00:00 2001 From: Jan <66554238+vaporox@users.noreply.github.com> Date: Mon, 5 Jul 2021 23:26:15 +0200 Subject: [PATCH] feat(Collector): better types for events (#6058) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Román --- typings/index.d.ts | 4 ++-- typings/index.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 656dd029b7e5..0efb5b3c1baf 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -391,10 +391,10 @@ export abstract class Collector extends EventEmi public abstract collect(...args: unknown[]): K | null | Promise; public abstract dispose(...args: unknown[]): K | null; - public on(event: 'collect' | 'dispose', listener: (...args: unknown[]) => Awaited): this; + public on(event: 'collect' | 'dispose', listener: (...args: [V, ...F]) => Awaited): this; public on(event: 'end', listener: (collected: Collection, reason: string) => Awaited): this; - public once(event: 'collect' | 'dispose', listener: (...args: unknown[]) => Awaited): this; + public once(event: 'collect' | 'dispose', listener: (...args: [V, ...F]) => Awaited): this; public once(event: 'end', listener: (collected: Collection, reason: string) => Awaited): this; } diff --git a/typings/index.ts b/typings/index.ts index 16f179cf875f..d1bcf5891b91 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -8,11 +8,14 @@ import { MessageActionRow, MessageAttachment, MessageButton, + MessageCollector, MessageEmbed, + MessageReaction, NewsChannel, Options, PartialTextBasedChannelFields, Permissions, + ReactionCollector, Serialized, ShardClientUtil, ShardingManager, @@ -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); +});