mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
types: fix cache types resolving to never (#7164)
This commit is contained in:
24
packages/discord.js/typings/index.d.ts
vendored
24
packages/discord.js/typings/index.d.ts
vendored
@@ -343,7 +343,7 @@ export abstract class BaseCommandInteraction<Cached extends CacheType = CacheTyp
|
||||
public ephemeral: boolean | null;
|
||||
public replied: boolean;
|
||||
public webhook: InteractionWebhook;
|
||||
public inGuild(): this is BaseCommandInteraction<'present'>;
|
||||
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<GuildCacheMessage<Cached>>;
|
||||
@@ -460,7 +460,7 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> 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<Cached extends Cach
|
||||
|
||||
export class CommandInteraction<Cached extends CacheType = CacheType> extends BaseCommandInteraction<Cached> {
|
||||
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 inRawGuild(): this is CommandInteraction<'raw'>;
|
||||
public toString(): string;
|
||||
@@ -735,7 +735,7 @@ export class AutocompleteInteraction<Cached extends CacheType = CacheType> exten
|
||||
public commandName: string;
|
||||
public responded: boolean;
|
||||
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 inRawGuild(): this is AutocompleteInteraction<'raw'>;
|
||||
private transformOption(option: APIApplicationCommandOption): CommandInteractionOption;
|
||||
@@ -816,7 +816,7 @@ export class ContextMenuInteraction<Cached extends CacheType = CacheType> extend
|
||||
>;
|
||||
public targetId: Snowflake;
|
||||
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 inRawGuild(): this is ContextMenuInteraction<'raw'>;
|
||||
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption<Cached>[];
|
||||
@@ -1285,7 +1285,7 @@ export class Intents extends BitField<IntentsString> {
|
||||
public static resolve(bit?: BitFieldResolvable<IntentsString, number>): number;
|
||||
}
|
||||
|
||||
export type CacheType = 'cached' | 'raw' | 'present';
|
||||
export type CacheType = 'cached' | 'raw' | undefined;
|
||||
|
||||
export type CacheTypeReducer<
|
||||
State extends CacheType,
|
||||
@@ -1297,7 +1297,7 @@ export type CacheTypeReducer<
|
||||
? CachedType
|
||||
: [State] extends ['raw']
|
||||
? RawType
|
||||
: [State] extends ['present']
|
||||
: [State] extends ['raw' | 'cached']
|
||||
? PresentType
|
||||
: Fallback;
|
||||
|
||||
@@ -1325,7 +1325,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
|
||||
public user: User;
|
||||
public version: number;
|
||||
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
|
||||
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<Cached>;
|
||||
@@ -1637,7 +1637,7 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
||||
public message: GuildCacheMessage<Cached>;
|
||||
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<GuildCacheMessage<Cached>>;
|
||||
@@ -1660,7 +1660,7 @@ export class MessageContextMenuInteraction<
|
||||
Cached extends CacheType = CacheType,
|
||||
> extends ContextMenuInteraction<Cached> {
|
||||
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 inRawGuild(): this is MessageContextMenuInteraction<'raw'>;
|
||||
}
|
||||
@@ -1974,7 +1974,7 @@ export class SelectMenuInteraction<Cached extends CacheType = CacheType> 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'>;
|
||||
}
|
||||
@@ -2400,7 +2400,7 @@ export class User extends PartialTextBasedChannel(Base) {
|
||||
export class UserContextMenuInteraction<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
|
||||
public readonly targetUser: User;
|
||||
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 inRawGuild(): this is UserContextMenuInteraction<'raw'>;
|
||||
}
|
||||
|
||||
@@ -942,7 +942,28 @@ expectDeprecated(sticker.deleted);
|
||||
// Test interactions
|
||||
declare const interaction: Interaction;
|
||||
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 => {
|
||||
if (interaction.inCachedGuild()) {
|
||||
|
||||
Reference in New Issue
Block a user