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

fix: await message component collectors should return component interactions not collectors #6562

Merged
merged 1 commit into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion typings/index.d.ts
Expand Up @@ -1135,6 +1135,14 @@ type InteractionCollectorReturnType<T extends MessageComponentType | MessageComp
? ConditionalInteractionCollectorType<MappedInteractionCollectorOptions[T]>
: InteractionCollector<MessageComponentInteraction>;

type InteractionReturnType<T extends MessageComponentType | MessageComponentTypes | undefined> = T extends
| MessageComponentType
| MessageComponentTypes
? MappedInteractionCollectorOptions[T] extends InteractionCollectorOptions<infer Item>
? Item
: never
: MessageComponentInteraction;

type MessageCollectorOptionsParams<T> =
| ({ componentType?: T } & InteractionCollectorOptionsResolvable)
| InteractionCollectorOptions<MessageComponentInteraction>;
Expand Down Expand Up @@ -1192,7 +1200,7 @@ export class Message extends Base {
public reference: MessageReference | null;
public awaitMessageComponent<T extends MessageComponentType | MessageComponentTypes | undefined = undefined>(
options?: AwaitMessageCollectorOptionsParams<T>,
): Promise<InteractionCollectorReturnType<T>>;
): Promise<InteractionReturnType<T>>;
public awaitReactions(options?: AwaitReactionsOptions): Promise<Collection<Snowflake | string, MessageReaction>>;
public createReactionCollector(options?: ReactionCollectorOptions): ReactionCollector;
public createMessageComponentCollector<
Expand Down
10 changes: 3 additions & 7 deletions typings/tests.ts
Expand Up @@ -494,21 +494,17 @@ client.on('messageCreate', message => {

// Verify that buttons interactions are inferred.
const buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' });
assertType<Promise<InteractionCollector<ButtonInteraction>>>(
message.awaitMessageComponent({ componentType: 'BUTTON' }),
);
assertType<Promise<ButtonInteraction>>(message.awaitMessageComponent({ componentType: 'BUTTON' }));
assertType<InteractionCollector<ButtonInteraction>>(buttonCollector);

// Verify that select menus interaction are inferred.
const selectMenuCollector = message.createMessageComponentCollector({ componentType: 'SELECT_MENU' });
assertType<Promise<InteractionCollector<SelectMenuInteraction>>>(
message.awaitMessageComponent({ componentType: 'SELECT_MENU' }),
);
assertType<Promise<SelectMenuInteraction>>(message.awaitMessageComponent({ componentType: 'SELECT_MENU' }));
assertType<InteractionCollector<SelectMenuInteraction>>(selectMenuCollector);

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

// Verify that additional options don't affect default collector types.
Expand Down