mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
feat: Backport cache types resolving to never (#7561)
This commit is contained in:
24
typings/index.d.ts
vendored
24
typings/index.d.ts
vendored
@@ -344,7 +344,7 @@ export abstract class BaseCommandInteraction<Cached extends CacheType = CacheTyp
|
|||||||
public ephemeral: boolean | null;
|
public ephemeral: boolean | null;
|
||||||
public replied: boolean;
|
public replied: boolean;
|
||||||
public webhook: InteractionWebhook;
|
public webhook: InteractionWebhook;
|
||||||
public inGuild(): this is BaseCommandInteraction<'present'>;
|
public inGuild(): this is BaseCommandInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is BaseCommandInteraction<'cached'>;
|
public inCachedGuild(): this is BaseCommandInteraction<'cached'>;
|
||||||
public inRawGuild(): this is BaseCommandInteraction<'raw'>;
|
public inRawGuild(): this is BaseCommandInteraction<'raw'>;
|
||||||
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
|
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
|
||||||
@@ -461,7 +461,7 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> extends Mes
|
|||||||
MessageButton | APIButtonComponent
|
MessageButton | APIButtonComponent
|
||||||
>;
|
>;
|
||||||
public componentType: 'BUTTON';
|
public componentType: 'BUTTON';
|
||||||
public inGuild(): this is ButtonInteraction<'present'>;
|
public inGuild(): this is ButtonInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is ButtonInteraction<'cached'>;
|
public inCachedGuild(): this is ButtonInteraction<'cached'>;
|
||||||
public inRawGuild(): this is ButtonInteraction<'raw'>;
|
public inRawGuild(): this is ButtonInteraction<'raw'>;
|
||||||
}
|
}
|
||||||
@@ -722,7 +722,7 @@ export interface ApplicationCommandInteractionOptionResolver<Cached extends Cach
|
|||||||
|
|
||||||
export class CommandInteraction<Cached extends CacheType = CacheType> extends BaseCommandInteraction<Cached> {
|
export class CommandInteraction<Cached extends CacheType = CacheType> extends BaseCommandInteraction<Cached> {
|
||||||
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage' | 'getFocused'>;
|
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage' | 'getFocused'>;
|
||||||
public inGuild(): this is CommandInteraction<'present'>;
|
public inGuild(): this is CommandInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is CommandInteraction<'cached'>;
|
public inCachedGuild(): this is CommandInteraction<'cached'>;
|
||||||
public inRawGuild(): this is CommandInteraction<'raw'>;
|
public inRawGuild(): this is CommandInteraction<'raw'>;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
@@ -735,7 +735,7 @@ export class AutocompleteInteraction<Cached extends CacheType = CacheType> exten
|
|||||||
public commandName: string;
|
public commandName: string;
|
||||||
public responded: boolean;
|
public responded: boolean;
|
||||||
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage'>;
|
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage'>;
|
||||||
public inGuild(): this is AutocompleteInteraction<'present'>;
|
public inGuild(): this is AutocompleteInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is AutocompleteInteraction<'cached'>;
|
public inCachedGuild(): this is AutocompleteInteraction<'cached'>;
|
||||||
public inRawGuild(): this is AutocompleteInteraction<'raw'>;
|
public inRawGuild(): this is AutocompleteInteraction<'raw'>;
|
||||||
private transformOption(option: APIApplicationCommandOption): CommandInteractionOption;
|
private transformOption(option: APIApplicationCommandOption): CommandInteractionOption;
|
||||||
@@ -821,7 +821,7 @@ export class ContextMenuInteraction<Cached extends CacheType = CacheType> extend
|
|||||||
>;
|
>;
|
||||||
public targetId: Snowflake;
|
public targetId: Snowflake;
|
||||||
public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>;
|
public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>;
|
||||||
public inGuild(): this is ContextMenuInteraction<'present'>;
|
public inGuild(): this is ContextMenuInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is ContextMenuInteraction<'cached'>;
|
public inCachedGuild(): this is ContextMenuInteraction<'cached'>;
|
||||||
public inRawGuild(): this is ContextMenuInteraction<'raw'>;
|
public inRawGuild(): this is ContextMenuInteraction<'raw'>;
|
||||||
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption<Cached>[];
|
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption<Cached>[];
|
||||||
@@ -1296,7 +1296,7 @@ export class Intents extends BitField<IntentsString> {
|
|||||||
public static resolve(bit?: BitFieldResolvable<IntentsString, number>): number;
|
public static resolve(bit?: BitFieldResolvable<IntentsString, number>): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CacheType = 'cached' | 'raw' | 'present';
|
export type CacheType = 'cached' | 'raw' | undefined;
|
||||||
|
|
||||||
export type CacheTypeReducer<
|
export type CacheTypeReducer<
|
||||||
State extends CacheType,
|
State extends CacheType,
|
||||||
@@ -1308,7 +1308,7 @@ export type CacheTypeReducer<
|
|||||||
? CachedType
|
? CachedType
|
||||||
: [State] extends ['raw']
|
: [State] extends ['raw']
|
||||||
? RawType
|
? RawType
|
||||||
: [State] extends ['present']
|
: [State] extends ['raw' | 'cached']
|
||||||
? PresentType
|
? PresentType
|
||||||
: Fallback;
|
: Fallback;
|
||||||
|
|
||||||
@@ -1338,7 +1338,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
|
|||||||
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
|
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
|
||||||
public locale: string;
|
public locale: string;
|
||||||
public guildLocale: CacheTypeReducer<Cached, string, string, string>;
|
public guildLocale: CacheTypeReducer<Cached, string, string, string>;
|
||||||
public inGuild(): this is Interaction<'present'>;
|
public inGuild(): this is Interaction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is Interaction<'cached'>;
|
public inCachedGuild(): this is Interaction<'cached'>;
|
||||||
public inRawGuild(): this is Interaction<'raw'>;
|
public inRawGuild(): this is Interaction<'raw'>;
|
||||||
public isApplicationCommand(): this is BaseCommandInteraction<Cached>;
|
public isApplicationCommand(): this is BaseCommandInteraction<Cached>;
|
||||||
@@ -1650,7 +1650,7 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
|||||||
public message: GuildCacheMessage<Cached>;
|
public message: GuildCacheMessage<Cached>;
|
||||||
public replied: boolean;
|
public replied: boolean;
|
||||||
public webhook: InteractionWebhook;
|
public webhook: InteractionWebhook;
|
||||||
public inGuild(): this is MessageComponentInteraction<'present'>;
|
public inGuild(): this is MessageComponentInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is MessageComponentInteraction<'cached'>;
|
public inCachedGuild(): this is MessageComponentInteraction<'cached'>;
|
||||||
public inRawGuild(): this is MessageComponentInteraction<'raw'>;
|
public inRawGuild(): this is MessageComponentInteraction<'raw'>;
|
||||||
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
|
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
|
||||||
@@ -1673,7 +1673,7 @@ export class MessageContextMenuInteraction<
|
|||||||
Cached extends CacheType = CacheType,
|
Cached extends CacheType = CacheType,
|
||||||
> extends ContextMenuInteraction<Cached> {
|
> extends ContextMenuInteraction<Cached> {
|
||||||
public readonly targetMessage: NonNullable<CommandInteractionOption<Cached>['message']>;
|
public readonly targetMessage: NonNullable<CommandInteractionOption<Cached>['message']>;
|
||||||
public inGuild(): this is MessageContextMenuInteraction<'present'>;
|
public inGuild(): this is MessageContextMenuInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is MessageContextMenuInteraction<'cached'>;
|
public inCachedGuild(): this is MessageContextMenuInteraction<'cached'>;
|
||||||
public inRawGuild(): this is MessageContextMenuInteraction<'raw'>;
|
public inRawGuild(): this is MessageContextMenuInteraction<'raw'>;
|
||||||
}
|
}
|
||||||
@@ -1987,7 +1987,7 @@ export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends
|
|||||||
>;
|
>;
|
||||||
public componentType: 'SELECT_MENU';
|
public componentType: 'SELECT_MENU';
|
||||||
public values: string[];
|
public values: string[];
|
||||||
public inGuild(): this is SelectMenuInteraction<'present'>;
|
public inGuild(): this is SelectMenuInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is SelectMenuInteraction<'cached'>;
|
public inCachedGuild(): this is SelectMenuInteraction<'cached'>;
|
||||||
public inRawGuild(): this is SelectMenuInteraction<'raw'>;
|
public inRawGuild(): this is SelectMenuInteraction<'raw'>;
|
||||||
}
|
}
|
||||||
@@ -2425,7 +2425,7 @@ export class User extends PartialTextBasedChannel(Base) {
|
|||||||
export class UserContextMenuInteraction<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
|
export class UserContextMenuInteraction<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
|
||||||
public readonly targetUser: User;
|
public readonly targetUser: User;
|
||||||
public readonly targetMember: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
|
public readonly targetMember: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
|
||||||
public inGuild(): this is UserContextMenuInteraction<'present'>;
|
public inGuild(): this is UserContextMenuInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is UserContextMenuInteraction<'cached'>;
|
public inCachedGuild(): this is UserContextMenuInteraction<'cached'>;
|
||||||
public inRawGuild(): this is UserContextMenuInteraction<'raw'>;
|
public inRawGuild(): this is UserContextMenuInteraction<'raw'>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -944,7 +944,28 @@ expectDeprecated(sticker.deleted);
|
|||||||
// Test interactions
|
// Test interactions
|
||||||
declare const interaction: Interaction;
|
declare const interaction: Interaction;
|
||||||
declare const booleanValue: boolean;
|
declare const booleanValue: boolean;
|
||||||
if (interaction.inGuild()) expectType<Snowflake>(interaction.guildId);
|
if (interaction.inGuild()) {
|
||||||
|
expectType<Snowflake>(interaction.guildId);
|
||||||
|
} else {
|
||||||
|
expectType<Snowflake | null>(interaction.guildId);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.on('interactionCreate', interaction => {
|
||||||
|
// This is for testing never type resolution
|
||||||
|
if (!interaction.inGuild()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interaction.inRawGuild()) {
|
||||||
|
expectNotType<never>(interaction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interaction.inCachedGuild()) {
|
||||||
|
expectNotType<never>(interaction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
client.on('interactionCreate', async interaction => {
|
client.on('interactionCreate', async interaction => {
|
||||||
if (interaction.inCachedGuild()) {
|
if (interaction.inCachedGuild()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user