types: message component cached props narrowing (#6809)

This commit is contained in:
Suneet Tipirneni
2021-10-12 15:11:37 -04:00
committed by GitHub
parent 6898fa3b37
commit b541d0a524
3 changed files with 62 additions and 29 deletions

64
typings/index.d.ts vendored
View File

@@ -276,14 +276,6 @@ export type GuildCacheMessage<Cached extends GuildCacheState> = CacheTypeReducer
Message | APIMessage
>;
export interface BaseGuildCommandInteraction<Cached extends GuildCacheState = GuildCacheState>
extends GuildInteraction<Cached> {
deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
fetchReply(): Promise<GuildCacheMessage<Cached>>;
reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
}
export abstract class BaseCommandInteraction extends Interaction {
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
public readonly channel: TextBasedChannels | null;
@@ -294,9 +286,9 @@ export abstract class BaseCommandInteraction extends Interaction {
public ephemeral: boolean | null;
public replied: boolean;
public webhook: InteractionWebhook;
public inGuild(): this is BaseGuildCommandInteraction<'present'> & this;
public inCachedGuild(): this is BaseGuildCommandInteraction<'cached'> & this;
public inRawGuild(): this is BaseGuildCommandInteraction<'raw'> & this;
public inGuild(): this is InteractionResponses<'present'> & this;
public inCachedGuild(): this is InteractionResponses<'cached'> & this;
public inRawGuild(): this is InteractionResponses<'raw'> & this;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deleteReply(): Promise<void>;
@@ -312,6 +304,21 @@ export abstract class BaseCommandInteraction extends Interaction {
private transformResolved(resolved: APIApplicationCommandInteractionData['resolved']): CommandInteractionResolvedData;
}
export interface InteractionResponsesResolvable {
inGuild(): this is InteractionResponses<'present'> & this;
inCachedGuild(): this is InteractionResponses<'cached'> & this;
inRawGuild(): this is InteractionResponses<'raw'> & this;
}
export type CacheHelper<
T extends Interaction,
Cached extends GuildCacheState,
> = T extends InteractionResponsesResolvable ? InteractionResponses<Cached> & T : GuildInteraction<Cached> & T;
export type GuildCached<T extends Interaction> = CacheHelper<T, 'cached'>;
export type GuildRaw<T extends Interaction> = CacheHelper<T, 'raw'>;
export type GuildPresent<T extends Interaction> = CacheHelper<T, 'present'>;
export abstract class BaseGuild extends Base {
protected constructor(client: Client, data: RawBaseGuildData);
public readonly createdAt: Date;
@@ -599,10 +606,7 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaitable<void>): this;
}
export type GuildCommandInteraction<Cached extends GuildCacheState = GuildCacheState> =
BaseGuildCommandInteraction<Cached> & CommandInteraction;
export class CommandInteraction extends BaseCommandInteraction implements GuildCachedInteraction<CommandInteraction> {
export class CommandInteraction extends BaseCommandInteraction {
public options: CommandInteractionOptionResolver;
public toString(): string;
}
@@ -662,20 +666,7 @@ export class CommandInteractionOptionResolver {
public getMessage(name: string, required: true): NonNullable<CommandInteractionOption['message']>;
public getMessage(name: string, required?: boolean): NonNullable<CommandInteractionOption['message']> | null;
}
export type GuildContextMenuInteraction<Cached extends GuildCacheState = GuildCacheState> =
BaseGuildCommandInteraction<Cached> & ContextMenuInteraction;
export interface GuildCachedInteraction<T> {
inGuild(): this is BaseGuildCommandInteraction<'present'> & T;
inCachedGuild(): this is BaseGuildCommandInteraction<'cached'> & T;
inRawGuild(): this is BaseGuildCommandInteraction<'raw'> & T;
}
export class ContextMenuInteraction
extends BaseCommandInteraction
implements GuildCachedInteraction<ContextMenuInteraction>
{
export class ContextMenuInteraction extends BaseCommandInteraction {
public options: CommandInteractionOptionResolver;
public targetId: Snowflake;
public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>;
@@ -1128,6 +1119,18 @@ export class Interaction extends Base {
public isSelectMenu(): this is SelectMenuInteraction;
}
export interface InteractionResponses<Cached extends GuildCacheState = GuildCacheState>
extends GuildInteraction<Cached> {
deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
deleteReply(): Promise<void>;
fetchReply(): Promise<GuildCacheMessage<Cached>>;
reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
}
export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T> {
public constructor(client: Client, options?: InteractionCollectorOptions<T>);
private _handleMessageDeletion(message: Message): void;
@@ -1421,6 +1424,9 @@ export class MessageComponentInteraction extends Interaction {
public message: Message | APIMessage;
public replied: boolean;
public webhook: InteractionWebhook;
public inGuild(): this is InteractionResponses<'present'> & this;
public inCachedGuild(): this is InteractionResponses<'cached'> & this;
public inRawGuild(): this is InteractionResponses<'raw'> & this;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<Message | APIMessage>;