Skip to content

Commit

Permalink
types: fix types and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Mar 25, 2022
1 parent 01a5896 commit 507ae60
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
3 changes: 0 additions & 3 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ export class ActionRowBuilder<
export type MessageActionRowComponent = ButtonComponent | SelectMenuComponent;
export type ModalActionRowComponent = TextInputComponent;

export type MessageActionRowBuilder = ButtonBuilder | SelectMenuBuilder;
export type ModalActionRowBuilder = TextInputBuilder;

export class ActionRow<T extends MessageActionRowComponent | ModalActionRowComponent> {
private constructor(data: APIActionRowComponent<APIMessageActionRowComponent>);
public readonly components: T[];
Expand Down
36 changes: 33 additions & 3 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ import {
ActionRowBuilder,
ButtonComponent,
SelectMenuComponent,
MessageActionRowBuilder,
InteractionResponseFields,
ThreadChannelType,
Events,
Expand All @@ -118,8 +117,10 @@ import {
TextInputBuilder,
TextInputComponent,
Embed,
MessageActionRowComponentBuilder,
} from '.';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
import { UnsafeButtonBuilder, UnsafeEmbedBuilder, UnsafeSelectMenuBuilder } from '@discordjs/builders';

// Test type transformation:
declare const serialize: <T>(value: T) => Serialized<T>;
Expand Down Expand Up @@ -727,6 +728,35 @@ client.on('messageCreate', async message => {
return true;
},
});

// Check that both builders and builder data can be sent in messages
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
const buttonsRow = {
type: ComponentType.ActionRow,
components: [
new ButtonBuilder(),
new UnsafeButtonBuilder(),
{ type: ComponentType.Button, label: 'test', style: ButtonStyle.Primary, customId: 'test' },
// TODO fix this test
// { type: ComponentType.Button, label: 'another test', style: ButtonStyle.Link, url: 'https://discord.js.org' },
],
};
const selectsRow = {
type: ComponentType.ActionRow,
components: [
new SelectMenuBuilder(),
new UnsafeSelectMenuBuilder(),
{
type: ComponentType.SelectMenu,
label: 'select menu',
options: [{ label: 'test', value: 'test' }],
customId: 'test',
},
],
};
const buildersEmbed = new UnsafeEmbedBuilder();
const embedData = { description: 'test', color: 0xff0000 };
channel.send({ components: [row, buttonsRow, selectsRow], embeds: [embed, buildersEmbed, embedData] });
});

client.on('threadMembersUpdate', (thread, addedMembers, removedMembers) => {
Expand All @@ -752,11 +782,11 @@ client.on('interactionCreate', async interaction => {

if (!interaction.isCommand()) return;

void new ActionRowBuilder<MessageActionRowBuilder>();
void new ActionRowBuilder<MessageActionRowComponentBuilder>();

const button = new ButtonBuilder();

const actionRow = new ActionRowBuilder<MessageActionRowBuilder>({
const actionRow = new ActionRowBuilder<MessageActionRowComponentBuilder>({
type: ComponentType.ActionRow,
components: [button.toJSON()],
});
Expand Down

0 comments on commit 507ae60

Please sign in to comment.