mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19: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 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>>;
|
||||||
@@ -460,7 +460,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;
|
||||||
@@ -816,7 +816,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>[];
|
||||||
@@ -1285,7 +1285,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,
|
||||||
@@ -1297,7 +1297,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;
|
||||||
|
|
||||||
@@ -1325,7 +1325,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
|
|||||||
public user: User;
|
public user: User;
|
||||||
public version: number;
|
public version: number;
|
||||||
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
|
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 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>;
|
||||||
@@ -1637,7 +1637,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>>;
|
||||||
@@ -1660,7 +1660,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'>;
|
||||||
}
|
}
|
||||||
@@ -1974,7 +1974,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'>;
|
||||||
}
|
}
|
||||||
@@ -2400,7 +2400,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'>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -942,7 +942,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