Skip to content

Commit

Permalink
types: add generic to ActionRowBuilder.from() (#8414)
Browse files Browse the repository at this point in the history
* types: add generic to `ActionRowBuilder#from()`

* test: add tests for `ActionRowBuilder.from()`

* tests: add more tests
  • Loading branch information
Syjalo committed Dec 23, 2022
1 parent 429dbcc commit 153352a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ export class ActionRowBuilder<T extends AnyComponentBuilder = AnyComponentBuilde
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
>,
);
public static from(
public static from<T extends AnyComponentBuilder = AnyComponentBuilder>(
other:
| JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>>
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>,
): ActionRowBuilder;
| JSONEncodable<APIActionRowComponent<ReturnType<T['toJSON']>>>
| APIActionRowComponent<ReturnType<T['toJSON']>>,
): ActionRowBuilder<T>;
}

export type MessageActionRowComponent =
Expand Down
22 changes: 22 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
APIEmbed,
ApplicationCommandType,
APIMessage,
APIActionRowComponent,
APIActionRowComponentTypes,
APIStringSelectComponent,
} from 'discord-api-types/v10';
import {
Expand Down Expand Up @@ -134,6 +136,8 @@ import {
Webhook,
WebhookClient,
InteractionWebhook,
ActionRowComponent,
ActionRow,
GuildAuditLogsActionType,
GuildAuditLogsTargetType,
ModalSubmitInteraction,
Expand Down Expand Up @@ -2046,6 +2050,24 @@ EmbedBuilder.from(embedData);
declare const embedComp: Embed;
EmbedBuilder.from(embedComp);

declare const actionRowData: APIActionRowComponent<APIActionRowComponentTypes>;
ActionRowBuilder.from(actionRowData);

declare const actionRowComp: ActionRow<ActionRowComponent>;
ActionRowBuilder.from(actionRowComp);

declare const buttonsActionRowData: APIActionRowComponent<APIButtonComponent>;
declare const buttonsActionRowComp: ActionRow<ButtonComponent>;

expectType<ActionRowBuilder<ButtonBuilder>>(ActionRowBuilder.from<ButtonBuilder>(buttonsActionRowData));
expectType<ActionRowBuilder<ButtonBuilder>>(ActionRowBuilder.from<ButtonBuilder>(buttonsActionRowComp));

declare const anyComponentsActionRowData: APIActionRowComponent<APIActionRowComponentTypes>;
declare const anyComponentsActionRowComp: ActionRow<ActionRowComponent>;

expectType<ActionRowBuilder>(ActionRowBuilder.from(anyComponentsActionRowData));
expectType<ActionRowBuilder>(ActionRowBuilder.from(anyComponentsActionRowComp));

declare const stageChannel: StageChannel;
declare const partialGroupDMChannel: PartialGroupDMChannel;

Expand Down

0 comments on commit 153352a

Please sign in to comment.