mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
types: Fix possibly null message properties (#7111)
This commit is contained in:
6
typings/index.d.ts
vendored
6
typings/index.d.ts
vendored
@@ -1566,7 +1566,7 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
|||||||
public channelId: Snowflake;
|
public channelId: Snowflake;
|
||||||
public deferred: boolean;
|
public deferred: boolean;
|
||||||
public ephemeral: boolean | null;
|
public ephemeral: boolean | null;
|
||||||
public message: CacheTypeReducer<Cached, Message, APIMessage>;
|
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<'present'>;
|
||||||
@@ -1591,7 +1591,7 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
|||||||
export class MessageContextMenuInteraction<
|
export class MessageContextMenuInteraction<
|
||||||
Cached extends CacheType = CacheType,
|
Cached extends CacheType = CacheType,
|
||||||
> extends ContextMenuInteraction<Cached> {
|
> extends ContextMenuInteraction<Cached> {
|
||||||
public readonly targetMessage: CacheTypeReducer<Cached, Message, APIMessage>;
|
public readonly targetMessage: NonNullable<CommandInteractionOption<Cached>['message']>;
|
||||||
public inGuild(): this is MessageContextMenuInteraction<'present'>;
|
public inGuild(): this is MessageContextMenuInteraction<'present'>;
|
||||||
public inCachedGuild(): this is MessageContextMenuInteraction<'cached'>;
|
public inCachedGuild(): this is MessageContextMenuInteraction<'cached'>;
|
||||||
public inRawGuild(): this is MessageContextMenuInteraction<'raw'>;
|
public inRawGuild(): this is MessageContextMenuInteraction<'raw'>;
|
||||||
@@ -3924,7 +3924,7 @@ export interface CommandInteractionOption<Cached extends CacheType = CacheType>
|
|||||||
member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>;
|
member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>;
|
||||||
channel?: CacheTypeReducer<Cached, GuildChannel | ThreadChannel, APIInteractionDataResolvedChannel>;
|
channel?: CacheTypeReducer<Cached, GuildChannel | ThreadChannel, APIInteractionDataResolvedChannel>;
|
||||||
role?: CacheTypeReducer<Cached, Role, APIRole>;
|
role?: CacheTypeReducer<Cached, Role, APIRole>;
|
||||||
message?: CacheTypeReducer<Cached, Message, APIMessage>;
|
message?: GuildCacheMessage<Cached>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CommandInteractionResolvedData<Cached extends CacheType = CacheType> {
|
export interface CommandInteractionResolvedData<Cached extends CacheType = CacheType> {
|
||||||
|
|||||||
@@ -968,22 +968,37 @@ client.on('interactionCreate', async interaction => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (interaction.isMessageContextMenu()) {
|
||||||
|
expectType<Message | APIMessage>(interaction.targetMessage);
|
||||||
|
if (interaction.inCachedGuild()) {
|
||||||
|
expectType<Message<true>>(interaction.targetMessage);
|
||||||
|
} else if (interaction.inRawGuild()) {
|
||||||
|
expectType<APIMessage>(interaction.targetMessage);
|
||||||
|
} else if (interaction.inGuild()) {
|
||||||
|
expectType<Message | APIMessage>(interaction.targetMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (interaction.isButton()) {
|
if (interaction.isButton()) {
|
||||||
expectType<ButtonInteraction>(interaction);
|
expectType<ButtonInteraction>(interaction);
|
||||||
expectType<MessageButton | APIButtonComponent>(interaction.component);
|
expectType<MessageButton | APIButtonComponent>(interaction.component);
|
||||||
|
expectType<Message | APIMessage>(interaction.message);
|
||||||
if (interaction.inCachedGuild()) {
|
if (interaction.inCachedGuild()) {
|
||||||
expectAssignable<ButtonInteraction>(interaction);
|
expectAssignable<ButtonInteraction>(interaction);
|
||||||
expectType<MessageButton>(interaction.component);
|
expectType<MessageButton>(interaction.component);
|
||||||
|
expectType<Message<true>>(interaction.message);
|
||||||
expectType<Guild>(interaction.guild);
|
expectType<Guild>(interaction.guild);
|
||||||
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
||||||
} else if (interaction.inRawGuild()) {
|
} else if (interaction.inRawGuild()) {
|
||||||
expectAssignable<ButtonInteraction>(interaction);
|
expectAssignable<ButtonInteraction>(interaction);
|
||||||
expectType<APIButtonComponent>(interaction.component);
|
expectType<APIButtonComponent>(interaction.component);
|
||||||
|
expectType<APIMessage>(interaction.message);
|
||||||
expectType<null>(interaction.guild);
|
expectType<null>(interaction.guild);
|
||||||
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||||
} else if (interaction.inGuild()) {
|
} else if (interaction.inGuild()) {
|
||||||
expectAssignable<ButtonInteraction>(interaction);
|
expectAssignable<ButtonInteraction>(interaction);
|
||||||
expectType<MessageButton | APIButtonComponent>(interaction.component);
|
expectType<MessageButton | APIButtonComponent>(interaction.component);
|
||||||
|
expectType<Message | APIMessage>(interaction.message);
|
||||||
expectAssignable<Guild | null>(interaction.guild);
|
expectAssignable<Guild | null>(interaction.guild);
|
||||||
expectType<Promise<APIMessage | Message>>(interaction.reply({ fetchReply: true }));
|
expectType<Promise<APIMessage | Message>>(interaction.reply({ fetchReply: true }));
|
||||||
}
|
}
|
||||||
@@ -992,19 +1007,23 @@ client.on('interactionCreate', async interaction => {
|
|||||||
if (interaction.isMessageComponent()) {
|
if (interaction.isMessageComponent()) {
|
||||||
expectType<MessageComponentInteraction>(interaction);
|
expectType<MessageComponentInteraction>(interaction);
|
||||||
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
||||||
|
expectType<Message | APIMessage>(interaction.message);
|
||||||
if (interaction.inCachedGuild()) {
|
if (interaction.inCachedGuild()) {
|
||||||
expectAssignable<MessageComponentInteraction>(interaction);
|
expectAssignable<MessageComponentInteraction>(interaction);
|
||||||
expectType<MessageActionRowComponent>(interaction.component);
|
expectType<MessageActionRowComponent>(interaction.component);
|
||||||
|
expectType<Message<true>>(interaction.message);
|
||||||
expectType<Guild>(interaction.guild);
|
expectType<Guild>(interaction.guild);
|
||||||
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
||||||
} else if (interaction.inRawGuild()) {
|
} else if (interaction.inRawGuild()) {
|
||||||
expectAssignable<MessageComponentInteraction>(interaction);
|
expectAssignable<MessageComponentInteraction>(interaction);
|
||||||
expectType<APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
expectType<APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
||||||
|
expectType<APIMessage>(interaction.message);
|
||||||
expectType<null>(interaction.guild);
|
expectType<null>(interaction.guild);
|
||||||
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||||
} else if (interaction.inGuild()) {
|
} else if (interaction.inGuild()) {
|
||||||
expectAssignable<MessageComponentInteraction>(interaction);
|
expectAssignable<MessageComponentInteraction>(interaction);
|
||||||
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
||||||
|
expectType<Message | APIMessage>(interaction.message);
|
||||||
expectType<Guild | null>(interaction.guild);
|
expectType<Guild | null>(interaction.guild);
|
||||||
expectType<Promise<APIMessage | Message>>(interaction.reply({ fetchReply: true }));
|
expectType<Promise<APIMessage | Message>>(interaction.reply({ fetchReply: true }));
|
||||||
}
|
}
|
||||||
@@ -1013,19 +1032,23 @@ client.on('interactionCreate', async interaction => {
|
|||||||
if (interaction.isSelectMenu()) {
|
if (interaction.isSelectMenu()) {
|
||||||
expectType<SelectMenuInteraction>(interaction);
|
expectType<SelectMenuInteraction>(interaction);
|
||||||
expectType<MessageSelectMenu | APISelectMenuComponent>(interaction.component);
|
expectType<MessageSelectMenu | APISelectMenuComponent>(interaction.component);
|
||||||
|
expectType<Message | APIMessage>(interaction.message);
|
||||||
if (interaction.inCachedGuild()) {
|
if (interaction.inCachedGuild()) {
|
||||||
expectAssignable<SelectMenuInteraction>(interaction);
|
expectAssignable<SelectMenuInteraction>(interaction);
|
||||||
expectType<MessageSelectMenu>(interaction.component);
|
expectType<MessageSelectMenu>(interaction.component);
|
||||||
|
expectType<Message<true>>(interaction.message);
|
||||||
expectType<Guild>(interaction.guild);
|
expectType<Guild>(interaction.guild);
|
||||||
expectType<Promise<Message<true>>>(interaction.reply({ fetchReply: true }));
|
expectType<Promise<Message<true>>>(interaction.reply({ fetchReply: true }));
|
||||||
} else if (interaction.inRawGuild()) {
|
} else if (interaction.inRawGuild()) {
|
||||||
expectAssignable<SelectMenuInteraction>(interaction);
|
expectAssignable<SelectMenuInteraction>(interaction);
|
||||||
expectType<APISelectMenuComponent>(interaction.component);
|
expectType<APISelectMenuComponent>(interaction.component);
|
||||||
|
expectType<APIMessage>(interaction.message);
|
||||||
expectType<null>(interaction.guild);
|
expectType<null>(interaction.guild);
|
||||||
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||||
} else if (interaction.inGuild()) {
|
} else if (interaction.inGuild()) {
|
||||||
expectAssignable<SelectMenuInteraction>(interaction);
|
expectAssignable<SelectMenuInteraction>(interaction);
|
||||||
expectType<MessageSelectMenu | APISelectMenuComponent>(interaction.component);
|
expectType<MessageSelectMenu | APISelectMenuComponent>(interaction.component);
|
||||||
|
expectType<Message | APIMessage>(interaction.message);
|
||||||
expectType<Guild | null>(interaction.guild);
|
expectType<Guild | null>(interaction.guild);
|
||||||
expectType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true }));
|
expectType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user