From a97a969ab12aa3470a8d9d48c29493512813422a Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Sat, 17 Feb 2024 18:36:35 +0100 Subject: [PATCH] fix(DiscordHeader): ensure that the level property is a number --- .../core/src/components/discord-header/DiscordHeader.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/src/components/discord-header/DiscordHeader.ts b/packages/core/src/components/discord-header/DiscordHeader.ts index 53719fbeb..7e9de6507 100644 --- a/packages/core/src/components/discord-header/DiscordHeader.ts +++ b/packages/core/src/components/discord-header/DiscordHeader.ts @@ -39,6 +39,12 @@ export class DiscordHeader extends LitElement { @property({ type: Number, reflect: true }) public accessor level: 1 | 2 | 3 = 1; + public ensureLevelIsNumber(): void { + if (this.level && !isNaN(this.level)) { + this.level = Number(this.level) as typeof this.level; + } + } + public checkLevel() { if (this.level < 1 || this.level > 3) { throw new RangeError('The level property must be a number between 1 and 3 (inclusive)'); @@ -46,6 +52,7 @@ export class DiscordHeader extends LitElement { } protected override render() { + this.ensureLevelIsNumber(); this.checkLevel(); switch (this.level) {