types: add generic to ActionRowBuilder.from() (#8414)

* types: add generic to `ActionRowBuilder#from()`

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

* tests: add more tests
This commit is contained in:
Synbulat Biishev
2022-12-23 22:57:20 +03:00
committed by GitHub
parent 429dbccc85
commit 153352ad7a
2 changed files with 26 additions and 4 deletions

View File

@@ -288,11 +288,11 @@ export class ActionRowBuilder<T extends AnyComponentBuilder = AnyComponentBuilde
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent> | APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
>, >,
); );
public static from( public static from<T extends AnyComponentBuilder = AnyComponentBuilder>(
other: other:
| JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>> | JSONEncodable<APIActionRowComponent<ReturnType<T['toJSON']>>>
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>, | APIActionRowComponent<ReturnType<T['toJSON']>>,
): ActionRowBuilder; ): ActionRowBuilder<T>;
} }
export type MessageActionRowComponent = export type MessageActionRowComponent =

View File

@@ -24,6 +24,8 @@ import {
APIEmbed, APIEmbed,
ApplicationCommandType, ApplicationCommandType,
APIMessage, APIMessage,
APIActionRowComponent,
APIActionRowComponentTypes,
APIStringSelectComponent, APIStringSelectComponent,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import { import {
@@ -134,6 +136,8 @@ import {
Webhook, Webhook,
WebhookClient, WebhookClient,
InteractionWebhook, InteractionWebhook,
ActionRowComponent,
ActionRow,
GuildAuditLogsActionType, GuildAuditLogsActionType,
GuildAuditLogsTargetType, GuildAuditLogsTargetType,
ModalSubmitInteraction, ModalSubmitInteraction,
@@ -2046,6 +2050,24 @@ EmbedBuilder.from(embedData);
declare const embedComp: Embed; declare const embedComp: Embed;
EmbedBuilder.from(embedComp); 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 stageChannel: StageChannel;
declare const partialGroupDMChannel: PartialGroupDMChannel; declare const partialGroupDMChannel: PartialGroupDMChannel;