Skip to content

Commit

Permalink
types(BaseButtonComponentData): Narrow component type (#9735)
Browse files Browse the repository at this point in the history
* types(BaseButtonComponentData): narrow `type`

* test: fix suddenly broken tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Jiralite and kodiakhq[bot] authored Aug 11, 2023
1 parent 632a9b4 commit a30d46c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5830,6 +5830,7 @@ export interface MessageActivity {
}

export interface BaseButtonComponentData extends BaseComponentData {
type: ComponentType.Button;
style: ButtonStyle;
disabled?: boolean;
emoji?: ComponentEmojiResolvable;
Expand Down
27 changes: 21 additions & 6 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ import {
ChatInputApplicationCommandData,
ApplicationCommandPermissionsManager,
GuildOnboarding,
StringSelectMenuComponentData,
ButtonComponentData,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -532,10 +534,10 @@ client.on('messageCreate', async message => {

// Check that both builders and builder data can be sent in messages
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
const buttonsRow: ActionRowData<MessageActionRowComponentData> = {

const rawButtonsRow: ActionRowData<ButtonComponentData> = {
type: ComponentType.ActionRow,
components: [
new ButtonBuilder(),
{ type: ComponentType.Button, label: 'test', style: ButtonStyle.Primary, customId: 'test' },
{
type: ComponentType.Button,
Expand All @@ -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,
components: [
new StringSelectMenuBuilder(),
{
type: ComponentType.StringSelect,
label: 'select menu',
options: [{ label: 'test', value: 'test' }],
customId: 'test',
},
],
};

const stringSelectRow: ActionRowData<StringSelectMenuBuilder> = {
type: ComponentType.ActionRow,
components: [new StringSelectMenuBuilder()],
};

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));
Expand Down

0 comments on commit a30d46c

Please sign in to comment.