mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
fix: only check instanceof Component once (#7546)
This commit is contained in:
@@ -17,13 +17,17 @@ export function createComponent<T extends keyof MappedComponentTypes>(
|
|||||||
): MappedComponentTypes[T];
|
): MappedComponentTypes[T];
|
||||||
export function createComponent<C extends MessageComponent>(data: C): C;
|
export function createComponent<C extends MessageComponent>(data: C): C;
|
||||||
export function createComponent(data: APIMessageComponent | MessageComponent): Component {
|
export function createComponent(data: APIMessageComponent | MessageComponent): Component {
|
||||||
|
if (data instanceof Component) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case ComponentType.ActionRow:
|
case ComponentType.ActionRow:
|
||||||
return (data instanceof ActionRow ? data : new ActionRow(data)) as Component;
|
return new ActionRow(data);
|
||||||
case ComponentType.Button:
|
case ComponentType.Button:
|
||||||
return (data instanceof ButtonComponent ? data : new ButtonComponent(data)) as Component;
|
return new ButtonComponent(data);
|
||||||
case ComponentType.SelectMenu:
|
case ComponentType.SelectMenu:
|
||||||
return (data instanceof SelectMenuComponent ? data : new SelectMenuComponent(data)) as Component;
|
return new SelectMenuComponent(data);
|
||||||
default:
|
default:
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
throw new Error(`Cannot serialize component type: ${data.type as number}`);
|
throw new Error(`Cannot serialize component type: ${data.type as number}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user