types(TextBasedChannels): fix awaitMessageComponent return type (#6723)

This commit is contained in:
muchnameless
2021-10-02 13:41:53 +02:00
committed by GitHub
parent 3a978f347c
commit a7cb314e07
2 changed files with 29 additions and 1 deletions

2
typings/index.d.ts vendored
View File

@@ -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,

View File

@@ -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.
@@ -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 => {