Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(BaseButtonComponentData): Narrow component type #9735

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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