types(BaseButtonComponentData): Narrow component type (#9735)

* types(BaseButtonComponentData): narrow `type`

* test: fix suddenly broken tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2023-08-11 08:15:05 +01:00
committed by GitHub
parent 632a9b4965
commit a30d46c5f5
2 changed files with 22 additions and 6 deletions

View File

@@ -5830,6 +5830,7 @@ export interface MessageActivity {
} }
export interface BaseButtonComponentData extends BaseComponentData { export interface BaseButtonComponentData extends BaseComponentData {
type: ComponentType.Button;
style: ButtonStyle; style: ButtonStyle;
disabled?: boolean; disabled?: boolean;
emoji?: ComponentEmojiResolvable; emoji?: ComponentEmojiResolvable;

View File

@@ -174,6 +174,8 @@ import {
ChatInputApplicationCommandData, ChatInputApplicationCommandData,
ApplicationCommandPermissionsManager, ApplicationCommandPermissionsManager,
GuildOnboarding, GuildOnboarding,
StringSelectMenuComponentData,
ButtonComponentData,
} from '.'; } from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@@ -532,10 +534,10 @@ client.on('messageCreate', async message => {
// Check that both builders and builder data can be sent in messages // Check that both builders and builder data can be sent in messages
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>(); const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
const buttonsRow: ActionRowData<MessageActionRowComponentData> = {
const rawButtonsRow: ActionRowData<ButtonComponentData> = {
type: ComponentType.ActionRow, type: ComponentType.ActionRow,
components: [ components: [
new ButtonBuilder(),
{ type: ComponentType.Button, label: 'test', style: ButtonStyle.Primary, customId: 'test' }, { type: ComponentType.Button, label: 'test', style: ButtonStyle.Primary, customId: 'test' },
{ {
type: ComponentType.Button, type: ComponentType.Button,
@@ -545,21 +547,34 @@ client.on('messageCreate', async message => {
}, },
], ],
}; };
const selectsRow: ActionRowData<MessageActionRowComponentData> = {
const buttonsRow: ActionRowData<ButtonBuilder> = {
type: ComponentType.ActionRow,
components: [new ButtonBuilder()],
};
const rawStringSelectMenuRow: ActionRowData<StringSelectMenuComponentData> = {
type: ComponentType.ActionRow, type: ComponentType.ActionRow,
components: [ components: [
new StringSelectMenuBuilder(),
{ {
type: ComponentType.StringSelect, type: ComponentType.StringSelect,
label: 'select menu',
options: [{ label: 'test', value: 'test' }], options: [{ label: 'test', value: 'test' }],
customId: 'test', customId: 'test',
}, },
], ],
}; };
const stringSelectRow: ActionRowData<StringSelectMenuBuilder> = {
type: ComponentType.ActionRow,
components: [new StringSelectMenuBuilder()],
};
const embedData = { description: 'test', color: 0xff0000 }; const embedData = { description: 'test', color: 0xff0000 };
channel.send({ components: [row, buttonsRow, selectsRow], embeds: [embed, embedData] });
channel.send({
components: [row, rawButtonsRow, buttonsRow, rawStringSelectMenuRow, stringSelectRow],
embeds: [embed, embedData],
});
}); });
client.on('messageDelete', ({ client }) => expectType<Client<true>>(client)); client.on('messageDelete', ({ client }) => expectType<Client<true>>(client));