From b8d511e3bffeeadff877eb9864cbb688a18b1701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Tue, 12 Mar 2024 00:15:05 -0400 Subject: [PATCH] fix: button builder types --- src/builders/Button.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/builders/Button.ts b/src/builders/Button.ts index d24fae2..bd192c8 100644 --- a/src/builders/Button.ts +++ b/src/builders/Button.ts @@ -1,7 +1,6 @@ import { throwError } from '..'; import { ComponentType, - type APIButtonComponent, type APIButtonComponentWithCustomId, type APIButtonComponentWithURL, type APIMessageComponentEmoji, @@ -13,6 +12,14 @@ import { resolvePartialEmoji } from '../structures/extra/functions'; export type ButtonStylesForID = Exclude; +export type ButtonSelect = T extends ButtonStyle.Link + ? Omit, 'setCustomId' | 'setURL' | 'setStyle'> & { + setStyle(style: ButtonStyle.Link): Omit, 'setCustomId' | 'setURL' | 'setStyle'>; + } + : Omit, 'setCustomId' | 'setURL' | 'setStyle'> & { + setStyle(style: ButtonStylesForID): Omit, 'setCustomId' | 'setURL' | 'setStyle'>; + }; + /** * Represents a button component. * @template Type - The type of the button component. @@ -31,10 +38,10 @@ export class Button { * @param id - The custom ID to set. * @returns The modified Button instance. */ - setCustomId(id: string) { + setCustomId(id: string): ButtonSelect { // @ts-expect-error this.data.custom_id = id; - return this; + return this as ButtonSelect; } /** @@ -42,10 +49,10 @@ export class Button { * @param url - The URL to set. * @returns The modified Button instance. */ - setURL(url: string) { + setURL(url: string): ButtonSelect { // @ts-expect-error this.data.url = url; - return this; + return this as ButtonSelect; } /** @@ -80,6 +87,8 @@ export class Button { return this; } + setStyle(style: ButtonStyle.Link): Omit; + setStyle(style: ButtonStylesForID): Omit; setStyle(style: ButtonStyle) { this.data.style = style; return this; @@ -90,6 +99,6 @@ export class Button { * @returns The JSON representation of the Button instance. */ toJSON() { - return { ...this.data } as unknown as APIButtonComponent; + return { ...this.data } as When; } }