diff --git a/typings/index.d.ts b/typings/index.d.ts index 14ccbf4f0342..51c60035f2d5 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -344,7 +344,7 @@ export abstract class BaseCommandInteraction; + public inGuild(): this is BaseCommandInteraction<'raw' | 'cached'>; public inCachedGuild(): this is BaseCommandInteraction<'cached'>; public inRawGuild(): this is BaseCommandInteraction<'raw'>; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise>; @@ -461,7 +461,7 @@ export class ButtonInteraction extends Mes MessageButton | APIButtonComponent >; public componentType: 'BUTTON'; - public inGuild(): this is ButtonInteraction<'present'>; + public inGuild(): this is ButtonInteraction<'raw' | 'cached'>; public inCachedGuild(): this is ButtonInteraction<'cached'>; public inRawGuild(): this is ButtonInteraction<'raw'>; } @@ -722,7 +722,7 @@ export interface ApplicationCommandInteractionOptionResolver extends BaseCommandInteraction { public options: Omit, 'getMessage' | 'getFocused'>; - public inGuild(): this is CommandInteraction<'present'>; + public inGuild(): this is CommandInteraction<'raw' | 'cached'>; public inCachedGuild(): this is CommandInteraction<'cached'>; public inRawGuild(): this is CommandInteraction<'raw'>; public toString(): string; @@ -735,7 +735,7 @@ export class AutocompleteInteraction exten public commandName: string; public responded: boolean; public options: Omit, 'getMessage'>; - public inGuild(): this is AutocompleteInteraction<'present'>; + public inGuild(): this is AutocompleteInteraction<'raw' | 'cached'>; public inCachedGuild(): this is AutocompleteInteraction<'cached'>; public inRawGuild(): this is AutocompleteInteraction<'raw'>; private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; @@ -821,7 +821,7 @@ export class ContextMenuInteraction extend >; public targetId: Snowflake; public targetType: Exclude; - public inGuild(): this is ContextMenuInteraction<'present'>; + public inGuild(): this is ContextMenuInteraction<'raw' | 'cached'>; public inCachedGuild(): this is ContextMenuInteraction<'cached'>; public inRawGuild(): this is ContextMenuInteraction<'raw'>; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; @@ -1296,7 +1296,7 @@ export class Intents extends BitField { public static resolve(bit?: BitFieldResolvable): number; } -export type CacheType = 'cached' | 'raw' | 'present'; +export type CacheType = 'cached' | 'raw' | undefined; export type CacheTypeReducer< State extends CacheType, @@ -1308,7 +1308,7 @@ export type CacheTypeReducer< ? CachedType : [State] extends ['raw'] ? RawType - : [State] extends ['present'] + : [State] extends ['raw' | 'cached'] ? PresentType : Fallback; @@ -1338,7 +1338,7 @@ export class Interaction extends Base { public memberPermissions: CacheTypeReducer>; public locale: string; public guildLocale: CacheTypeReducer; - public inGuild(): this is Interaction<'present'>; + public inGuild(): this is Interaction<'raw' | 'cached'>; public inCachedGuild(): this is Interaction<'cached'>; public inRawGuild(): this is Interaction<'raw'>; public isApplicationCommand(): this is BaseCommandInteraction; @@ -1650,7 +1650,7 @@ export class MessageComponentInteraction e public message: GuildCacheMessage; public replied: boolean; public webhook: InteractionWebhook; - public inGuild(): this is MessageComponentInteraction<'present'>; + public inGuild(): this is MessageComponentInteraction<'raw' | 'cached'>; public inCachedGuild(): this is MessageComponentInteraction<'cached'>; public inRawGuild(): this is MessageComponentInteraction<'raw'>; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise>; @@ -1673,7 +1673,7 @@ export class MessageContextMenuInteraction< Cached extends CacheType = CacheType, > extends ContextMenuInteraction { public readonly targetMessage: NonNullable['message']>; - public inGuild(): this is MessageContextMenuInteraction<'present'>; + public inGuild(): this is MessageContextMenuInteraction<'raw' | 'cached'>; public inCachedGuild(): this is MessageContextMenuInteraction<'cached'>; public inRawGuild(): this is MessageContextMenuInteraction<'raw'>; } @@ -1987,7 +1987,7 @@ export class SelectMenuInteraction extends >; public componentType: 'SELECT_MENU'; public values: string[]; - public inGuild(): this is SelectMenuInteraction<'present'>; + public inGuild(): this is SelectMenuInteraction<'raw' | 'cached'>; public inCachedGuild(): this is SelectMenuInteraction<'cached'>; public inRawGuild(): this is SelectMenuInteraction<'raw'>; } @@ -2425,7 +2425,7 @@ export class User extends PartialTextBasedChannel(Base) { export class UserContextMenuInteraction extends ContextMenuInteraction { public readonly targetUser: User; public readonly targetMember: CacheTypeReducer; - public inGuild(): this is UserContextMenuInteraction<'present'>; + public inGuild(): this is UserContextMenuInteraction<'raw' | 'cached'>; public inCachedGuild(): this is UserContextMenuInteraction<'cached'>; public inRawGuild(): this is UserContextMenuInteraction<'raw'>; } diff --git a/typings/index.test-d.ts b/typings/index.test-d.ts index d20c82162089..9d9281bc1422 100644 --- a/typings/index.test-d.ts +++ b/typings/index.test-d.ts @@ -944,7 +944,28 @@ expectDeprecated(sticker.deleted); // Test interactions declare const interaction: Interaction; declare const booleanValue: boolean; -if (interaction.inGuild()) expectType(interaction.guildId); +if (interaction.inGuild()) { + expectType(interaction.guildId); +} else { + expectType(interaction.guildId); +} + +client.on('interactionCreate', interaction => { + // This is for testing never type resolution + if (!interaction.inGuild()) { + return; + } + + if (interaction.inRawGuild()) { + expectNotType(interaction); + return; + } + + if (interaction.inCachedGuild()) { + expectNotType(interaction); + return; + } +}); client.on('interactionCreate', async interaction => { if (interaction.inCachedGuild()) {