From 0aa48516a4e33497e8e8dc50da164a57cdee09d3 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Sat, 26 Feb 2022 05:14:04 -0500 Subject: [PATCH] fix: only check `instanceof Component` once (#7546) --- packages/builders/src/components/Components.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/builders/src/components/Components.ts b/packages/builders/src/components/Components.ts index cb61639bb545..d9d60199dd15 100644 --- a/packages/builders/src/components/Components.ts +++ b/packages/builders/src/components/Components.ts @@ -17,13 +17,17 @@ export function createComponent( ): MappedComponentTypes[T]; export function createComponent(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}`);