diff --git a/typings/index.d.ts b/typings/index.d.ts index d07cadcb6..925e3f72a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1310,68 +1310,40 @@ export class LimitedCollection extends Collection { public static filterByLifetime(options?: LifetimeFilterOptions): SweepFilter; } -// This is a general conditional type utility that allows for specific union members to be extracted given -// a tagged union. -export type TaggedUnion = T extends Record - ? T - : T extends Record - ? V extends U - ? T - : never - : never; - -// This creates a map of MessageComponentTypes to their respective `InteractionCollectorOptionsResolvable` variant. -export type CollectorOptionsTypeResolver, Cached = boolean> = { - readonly [T in U['componentType']]: TaggedUnion; -}; - -// This basically says "Given a `InteractionCollectorOptionsResolvable` variant", I'll give the corresponding -// `InteractionCollector` variant back. -export type ConditionalInteractionCollectorType = - T extends InteractionCollectorOptions - ? InteractionCollector - : InteractionCollector; - -// This maps each componentType key to each variant. -export type MappedInteractionCollectorOptions = CollectorOptionsTypeResolver< - InteractionCollectorOptionsResolvable, - Cached ->; - -// Converts mapped types to complimentary collector types. -export type InteractionCollectorReturnType< - T extends MessageComponentType | MessageComponentTypes | undefined, - Cached extends boolean = false, -> = T extends MessageComponentType | MessageComponentTypes - ? ConditionalInteractionCollectorType[T]> - : InteractionCollector; - -export type InteractionExtractor< - T extends MessageComponentType | MessageComponentTypes | undefined, - C extends boolean = false, -> = T extends MessageComponentType | MessageComponentTypes - ? MappedInteractionCollectorOptions[T] extends InteractionCollectorOptions - ? Item - : never - : MessageComponentInteraction; - -export type MessageCollectorOptionsParams = +export type MessageCollectorOptionsParams = | { componentType?: T; - } & MessageComponentCollectorOptions>; + } & MessageComponentCollectorOptions; -export type MessageChannelCollectorOptionsParams = +export type MessageChannelCollectorOptionsParams = | { componentType?: T; - } & MessageChannelComponentCollectorOptions>; + } & MessageChannelComponentCollectorOptions; -export type AwaitMessageCollectorOptionsParams = +export type AwaitMessageCollectorOptionsParams = | { componentType?: T } & Pick< - InteractionCollectorOptions>, + InteractionCollectorOptions, keyof AwaitMessageComponentOptions >; export type GuildTextBasedChannel = Exclude; +export interface StringMappedInteractionTypes { + BUTTON: ButtonInteraction; + SELECT_MENU: SelectMenuInteraction; + ACTION_ROW: MessageComponentInteraction; +} + +export interface EnumMappedInteractionTypes { + 1: MessageComponentInteraction; + 2: ButtonInteraction; + 3: SelectMenuInteraction; +} + +export type WrapBooleanCache = If; +export type MappedInteractionTypes = StringMappedInteractionTypes< + WrapBooleanCache +> & + EnumMappedInteractionTypes>; export class Message extends Base { private readonly _cacheType: Cached; @@ -1418,14 +1390,14 @@ export class Message extends Base { public webhookId: Snowflake | null; public flags: Readonly; public reference: MessageReference | null; - public awaitMessageComponent< - T extends MessageComponentType | MessageComponentTypes | undefined = MessageComponentTypes.ACTION_ROW, - >(options?: AwaitMessageCollectorOptionsParams): Promise>; + public awaitMessageComponent( + options?: AwaitMessageCollectorOptionsParams, + ): Promise[T]>; public awaitReactions(options?: AwaitReactionsOptions): Promise>; public createReactionCollector(options?: ReactionCollectorOptions): ReactionCollector; - public createMessageComponentCollector< - T extends MessageComponentType | MessageComponentTypes | undefined = undefined, - >(options?: MessageCollectorOptionsParams): InteractionCollectorReturnType; + public createMessageComponentCollector( + options?: MessageCollectorOptionsParams, + ): InteractionCollector[T]>; public delete(): Promise; public edit(content: string | MessageEditOptions | MessagePayload): Promise; public equals(message: Message, rawData: unknown): boolean; @@ -3048,17 +3020,17 @@ export interface TextBasedChannelFields extends PartialTextBasedChannelFields { readonly lastMessage: Message | null; lastPinTimestamp: number | null; readonly lastPinAt: Date | null; - awaitMessageComponent( + awaitMessageComponent( options?: AwaitMessageCollectorOptionsParams, - ): Promise>; + ): Promise; awaitMessages(options?: AwaitMessagesOptions): Promise>; bulkDelete( messages: Collection | readonly MessageResolvable[] | number, filterOld?: boolean, ): Promise>; - createMessageComponentCollector( + createMessageComponentCollector( options?: MessageChannelCollectorOptionsParams, - ): InteractionCollectorReturnType; + ): InteractionCollector; createMessageCollector(options?: MessageCollectorOptions): MessageCollector; sendTyping(): Promise; }