Skip to content

Commit

Permalink
types(TextBasedChannels): fix awaitMessageComponent return type (#6723)
Browse files Browse the repository at this point in the history
  • Loading branch information
muchnameless authored Oct 2, 2021
1 parent 3a978f3 commit a7cb314
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,7 @@ export interface TextBasedChannelFields extends PartialTextBasedChannelFields {
readonly lastPinAt: Date | null;
awaitMessageComponent<T extends MessageComponentType | MessageComponentTypes | undefined = undefined>(
options?: AwaitMessageCollectorOptionsParams<T>,
): Promise<InteractionCollectorReturnType<T>>;
): Promise<InteractionExtractor<T>>;
awaitMessages(options?: AwaitMessagesOptions): Promise<Collection<Snowflake, Message>>;
bulkDelete(
messages: Collection<Snowflake, Message> | readonly MessageResolvable[] | number,
Expand Down
28 changes: 28 additions & 0 deletions typings/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,21 +498,26 @@ client.on('messageCreate', message => {
// Verify that buttons interactions are inferred.
const buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' });
assertType<Promise<ButtonInteraction>>(message.awaitMessageComponent({ componentType: 'BUTTON' }));
assertType<Promise<ButtonInteraction>>(channel.awaitMessageComponent({ componentType: 'BUTTON' }));
assertType<InteractionCollector<ButtonInteraction>>(buttonCollector);

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

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

// Verify that additional options don't affect default collector types.
const semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 });
assertType<InteractionCollector<MessageComponentInteraction>>(semiDefaultCollector);
const semiDefaultCollectorChannel = message.createMessageComponentCollector({ time: 10000 });
assertType<InteractionCollector<MessageComponentInteraction>>(semiDefaultCollectorChannel);

// Verify that interaction collector options can't be used.

Expand Down Expand Up @@ -565,6 +570,29 @@ client.on('messageCreate', message => {
return true;
},
});

channel.awaitMessageComponent({
filter: i => {
assertType<MessageComponentInteraction>(i);
return true;
},
});

channel.awaitMessageComponent({
componentType: 'BUTTON',
filter: i => {
assertType<ButtonInteraction>(i);
return true;
},
});

channel.awaitMessageComponent({
componentType: 'SELECT_MENU',
filter: i => {
assertType<SelectMenuInteraction>(i);
return true;
},
});
});

client.on('interaction', async interaction => {
Expand Down

0 comments on commit a7cb314

Please sign in to comment.