mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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:
1
packages/discord.js/typings/index.d.ts
vendored
1
packages/discord.js/typings/index.d.ts
vendored
@@ -5830,6 +5830,7 @@ export interface MessageActivity {
|
||||
}
|
||||
|
||||
export interface BaseButtonComponentData extends BaseComponentData {
|
||||
type: ComponentType.Button;
|
||||
style: ButtonStyle;
|
||||
disabled?: boolean;
|
||||
emoji?: ComponentEmojiResolvable;
|
||||
|
||||
@@ -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';
|
||||
@@ -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,
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user