From b880340d79da89edfb6d24ee8f421ba58f3f6551 Mon Sep 17 00:00:00 2001 From: Vaporox Date: Mon, 5 Jul 2021 21:12:17 +0200 Subject: [PATCH 1/2] feat(Collector): better types for events --- 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 6628bcb64ff5..3a2acf15f22e 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..2132c49f769a 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 mc: MessageCollector; +mc.on('collect', (...args) => { + assertType<[Message]>(args); +}); + +declare const rc: ReactionCollector; +rc.on('dispose', (...args) => { + assertType<[MessageReaction, User]>(args); +}); From 67860c6095d0d8a57399a5223d6a47a62821e414 Mon Sep 17 00:00:00 2001 From: Jan <66554238+vaporox@users.noreply.github.com> Date: Mon, 5 Jul 2021 21:55:38 +0200 Subject: [PATCH 2/2] refactor: better variable names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Román --- typings/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/typings/index.ts b/typings/index.ts index 2132c49f769a..d1bcf5891b91 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -494,12 +494,12 @@ notPropertyOf(guildMember, 'lastMessage'); notPropertyOf(guildMember, 'lastMessageId'); // Test collector event parameters -declare const mc: MessageCollector; -mc.on('collect', (...args) => { +declare const messageCollector: MessageCollector; +messageCollector.on('collect', (...args) => { assertType<[Message]>(args); }); -declare const rc: ReactionCollector; -rc.on('dispose', (...args) => { +declare const reactionCollector: ReactionCollector; +reactionCollector.on('dispose', (...args) => { assertType<[MessageReaction, User]>(args); });