Skip to content

Commit

Permalink
fix: don't require the user to cast types for button styles
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilloftheshadow committed Sep 18, 2024
1 parent a0074f0 commit 77b71ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-gifts-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@buape/carbon": patch
---

fix: don't require the user to cast types for button styles
2 changes: 1 addition & 1 deletion apps/rocko/src/commands/testing/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class ButtonCommand extends Command {
class PingButton extends Button {
customId = "ping"
label = "Ping"
style = ButtonStyle.Primary as typeof Button.prototype.style
style = ButtonStyle.Primary

async run(interaction: ButtonInteraction) {
await interaction.reply({ content: "OMG YOU CLICKED THE BUTTON" })
Expand Down
15 changes: 10 additions & 5 deletions packages/carbon/src/classes/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ abstract class BaseButton extends BaseComponent {
}

export abstract class Button extends BaseButton {
/**
* The style of the button
*/
abstract style: Exclude<ButtonStyle, ButtonStyle.Link | ButtonStyle.Premium>

abstract run(interaction: ButtonInteraction): Promise<void>

serialize = (): APIButtonComponent => {
if (this.style === ButtonStyle.Link) {
throw new Error(
"Link buttons cannot be serialized. Are you using the right class?"
)
}
if (this.style === ButtonStyle.Premium) {
throw new Error(
"Premium buttons cannot be serialized. Are you using the right class?"
)
}
return {
type: ComponentType.Button,
style: this.style,
Expand Down

0 comments on commit 77b71ef

Please sign in to comment.