types: fix component *Data types (#7536)

This commit is contained in:
Suneet Tipirneni
2022-02-26 05:17:03 -05:00
committed by GitHub
parent 1a14c0ca56
commit a8321d8026
2 changed files with 28 additions and 4 deletions

View File

@@ -204,7 +204,11 @@ export interface ActionRowData extends BaseComponentData {
}
export class ActionRow<T extends ActionRowComponent = ActionRowComponent> extends BuilderActionRow<T> {
constructor(data?: ActionRowData | APIActionRowComponent<APIMessageComponent>);
constructor(
data?:
| ActionRowData
| (Omit<APIActionRowComponent<APIMessageComponent>, 'type'> & { type?: ComponentType.ActionRow }),
);
}
export class ActivityFlagsBitField extends BitField<ActivityFlagsString> {
@@ -473,11 +477,13 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> extends Mes
}
export class ButtonComponent extends BuilderButtonComponent {
public constructor(data?: ButtonComponentData | APIButtonComponent);
public constructor(data?: ButtonComponentData | (Omit<APIButtonComponent, 'type'> & { type?: ComponentType.Button }));
}
export class SelectMenuComponent extends BuilderSelectMenuComponent {
public constructor(data?: SelectMenuComponentData | APISelectMenuComponent);
public constructor(
data?: SelectMenuComponentData | (Omit<APISelectMenuComponent, 'type'> & { type?: ComponentType.SelectMenu }),
);
}
export interface EmbedData {
@@ -4619,7 +4625,7 @@ export interface MessageReference {
export type MessageResolvable = Message | Snowflake;
export interface SelectMenuComponentData extends BaseComponentData {
customId?: string;
customId: string;
disabled?: boolean;
maxValues?: number;
minValues?: number;

View File

@@ -103,6 +103,7 @@ import {
ShardEvents,
Status,
CategoryChannelChildManager,
ActionRowData,
} from '.';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
import { Embed } from '@discordjs/builders';
@@ -1309,6 +1310,23 @@ new ActionRow({
components: [selectMenu.toJSON(), button.toJSON()],
});
new SelectMenuComponent({
customId: 'foo',
});
new ButtonComponent({
style: ButtonStyle.Danger,
});
expectNotAssignable<ActionRowData>({
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
},
],
});
declare const chatInputInteraction: ChatInputCommandInteraction;
expectType<MessageAttachment>(chatInputInteraction.options.getAttachment('attachment', true));