Skip to content

Commit 7d99d99

Browse files
committed
fix(discord-button): fixed button type checking to be null safe
1 parent 84e5bc4 commit 7d99d99

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/core/src/components/discord-button/DiscordButton.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,15 @@ export class DiscordButton extends LitElement implements DiscordButtonProps {
118118
@property({ reflect: true, attribute: 'type' })
119119
public accessor type: 'destructive' | 'primary' | 'secondary' | 'success' = 'secondary';
120120

121+
private readonly validButtonTypes = new Set(['primary', 'secondary', 'success', 'destructive']);
122+
121123
public checkType() {
122-
if (typeof this.type !== 'string') {
123-
throw new TypeError('DiscordButton `type` prop must be a string.');
124-
} else if (!['primary', 'secondary', 'success', 'destructive'].includes(this.type)) {
125-
throw new RangeError("DiscordButton `type` prop must be one of: 'primary', 'secondary', 'success', 'destructive'");
124+
if (this.type) {
125+
if (typeof this.type !== 'string') {
126+
throw new TypeError('DiscordButton `type` prop must be a string.');
127+
} else if (!this.validButtonTypes.has(this.type)) {
128+
throw new RangeError("DiscordButton `type` prop must be one of: 'primary', 'secondary', 'success', 'destructive'");
129+
}
126130
}
127131
}
128132

0 commit comments

Comments
 (0)