Skip to content

Commit a30d46c

Browse files
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>
1 parent 632a9b4 commit a30d46c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

packages/discord.js/typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5830,6 +5830,7 @@ export interface MessageActivity {
58305830
}
58315831

58325832
export interface BaseButtonComponentData extends BaseComponentData {
5833+
type: ComponentType.Button;
58335834
style: ButtonStyle;
58345835
disabled?: boolean;
58355836
emoji?: ComponentEmojiResolvable;

packages/discord.js/typings/index.test-d.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ import {
174174
ChatInputApplicationCommandData,
175175
ApplicationCommandPermissionsManager,
176176
GuildOnboarding,
177+
StringSelectMenuComponentData,
178+
ButtonComponentData,
177179
} from '.';
178180
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
179181
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@@ -532,10 +534,10 @@ client.on('messageCreate', async message => {
532534

533535
// Check that both builders and builder data can be sent in messages
534536
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
535-
const buttonsRow: ActionRowData<MessageActionRowComponentData> = {
537+
538+
const rawButtonsRow: ActionRowData<ButtonComponentData> = {
536539
type: ComponentType.ActionRow,
537540
components: [
538-
new ButtonBuilder(),
539541
{ type: ComponentType.Button, label: 'test', style: ButtonStyle.Primary, customId: 'test' },
540542
{
541543
type: ComponentType.Button,
@@ -545,21 +547,34 @@ client.on('messageCreate', async message => {
545547
},
546548
],
547549
};
548-
const selectsRow: ActionRowData<MessageActionRowComponentData> = {
550+
551+
const buttonsRow: ActionRowData<ButtonBuilder> = {
552+
type: ComponentType.ActionRow,
553+
components: [new ButtonBuilder()],
554+
};
555+
556+
const rawStringSelectMenuRow: ActionRowData<StringSelectMenuComponentData> = {
549557
type: ComponentType.ActionRow,
550558
components: [
551-
new StringSelectMenuBuilder(),
552559
{
553560
type: ComponentType.StringSelect,
554-
label: 'select menu',
555561
options: [{ label: 'test', value: 'test' }],
556562
customId: 'test',
557563
},
558564
],
559565
};
560566

567+
const stringSelectRow: ActionRowData<StringSelectMenuBuilder> = {
568+
type: ComponentType.ActionRow,
569+
components: [new StringSelectMenuBuilder()],
570+
};
571+
561572
const embedData = { description: 'test', color: 0xff0000 };
562-
channel.send({ components: [row, buttonsRow, selectsRow], embeds: [embed, embedData] });
573+
574+
channel.send({
575+
components: [row, rawButtonsRow, buttonsRow, rawStringSelectMenuRow, stringSelectRow],
576+
embeds: [embed, embedData],
577+
});
563578
});
564579

565580
client.on('messageDelete', ({ client }) => expectType<Client<true>>(client));

0 commit comments

Comments
 (0)