Skip to content

Commit

Permalink
fix: only check instanceof Component once (#7546)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Feb 26, 2022
1 parent 8346003 commit 0aa4851
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/builders/src/components/Components.ts
Expand Up @@ -17,13 +17,17 @@ export function createComponent<T extends keyof MappedComponentTypes>(
): MappedComponentTypes[T];
export function createComponent<C extends MessageComponent>(data: C): C;
export function createComponent(data: APIMessageComponent | MessageComponent): Component {
if (data instanceof Component) {
return data;
}

switch (data.type) {
case ComponentType.ActionRow:
return (data instanceof ActionRow ? data : new ActionRow(data)) as Component;
return new ActionRow(data);
case ComponentType.Button:
return (data instanceof ButtonComponent ? data : new ButtonComponent(data)) as Component;
return new ButtonComponent(data);
case ComponentType.SelectMenu:
return (data instanceof SelectMenuComponent ? data : new SelectMenuComponent(data)) as Component;
return new SelectMenuComponent(data);
default:
// @ts-expect-error
throw new Error(`Cannot serialize component type: ${data.type as number}`);
Expand Down

0 comments on commit 0aa4851

Please sign in to comment.