From 907fe76e23a73e5f6ba5b38bb72d915f401d757a Mon Sep 17 00:00:00 2001 From: arch-fan Date: Sat, 6 Jan 2024 22:45:48 +0100 Subject: [PATCH 1/2] Fix: TypeScript error, property 'hint' doesn't exist on type 'Error'. Created new class for error. --- packages/core/components/Icon.astro | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/core/components/Icon.astro b/packages/core/components/Icon.astro index 34f402e8..075b4234 100644 --- a/packages/core/components/Icon.astro +++ b/packages/core/components/Icon.astro @@ -15,6 +15,14 @@ interface Props extends HTMLAttributes<"svg"> { height?: number; } +class AstroIconError extends Error { + public hint: string; + + constructor(message: string) { + super(message); + } +} + const req = Astro.request; const { name = "", title, ...props } = Astro.props; const map = cache.get(req) ?? new Map(); @@ -30,7 +38,7 @@ const includeSymbol = i === 0; let [setName, iconName] = (name as string).split(":"); if (!setName && iconName) { - const err = new Error(`Invalid "name" provided!`); + const err = new AstroIconError(`Invalid "name" provided!`); if (import.meta.env.DEV) { err.hint = `The provided value of "${name}" is invalid.\n\nDid you forget the icon set name? If you were attemping to reference a local icon, use the icon's name directly. (ie. "${providedIconName}")`; } @@ -45,7 +53,7 @@ if (!iconName) { // Check if the local icon set exists if (!icons[setName]) { - const err = new Error('Unable to load the "local" icon set!'); + const err = new AstroIconError('Unable to load the "local" icon set!'); if (import.meta.env.DEV) { err.hint = 'It looks like the "local" set was not loaded.\n\nDid you forget to create the icon directory or to update your config?'; @@ -55,7 +63,7 @@ if (!iconName) { // Check if the icon is missing from the local collection if (!(iconName in icons[setName].icons)) { - const err = new Error(`Unable to locate "${name}" icon!`); + const err = new AstroIconError(`Unable to locate "${name}" icon!`); if (import.meta.env.DEV) { err.hint = `The icon named "${iconName}" was not found in your local icon directory.\n\nDid you forget to configure your icon directory or make a typo?`; } @@ -67,7 +75,7 @@ const collection = icons[setName]; // Iconify collection not configured correctly if (!collection) { - const err = new Error(`Unable to locate the "${setName}" icon set!`); + const err = new AstroIconError(`Unable to locate the "${setName}" icon set!`); if (import.meta.env.DEV) { if (sets.includes(setName)) { err.hint = `It looks like the "${setName}" set was not loaded.\n\nDid you install the "@iconify-json/${setName}" dependency?`; @@ -81,7 +89,7 @@ if (!collection) { const iconData = getIconData(collection, iconName ?? setName); // Missing icon from the icon collection if (!iconData) { - const err = new Error(`Unable to locate "${name}" icon!`); + const err = new AstroIconError(`Unable to locate "${name}" icon!`); if (import.meta.env.DEV) { const [maybeStar] = include[setName]; if (maybeStar === "*" || include[setName].includes(iconName)) { From 0b61125c34e08d8dbd8be329cd95bad87155baa6 Mon Sep 17 00:00:00 2001 From: arch-fan Date: Sat, 6 Jan 2024 22:46:47 +0100 Subject: [PATCH 2/2] Fix: TypeScript error, The name 'providedIconName' isn't found. Using right variable name. --- packages/core/components/Icon.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/components/Icon.astro b/packages/core/components/Icon.astro index 075b4234..3f2c5e5f 100644 --- a/packages/core/components/Icon.astro +++ b/packages/core/components/Icon.astro @@ -40,7 +40,7 @@ let [setName, iconName] = (name as string).split(":"); if (!setName && iconName) { const err = new AstroIconError(`Invalid "name" provided!`); if (import.meta.env.DEV) { - err.hint = `The provided value of "${name}" is invalid.\n\nDid you forget the icon set name? If you were attemping to reference a local icon, use the icon's name directly. (ie. "${providedIconName}")`; + err.hint = `The provided value of "${name}" is invalid.\n\nDid you forget the icon set name? If you were attemping to reference a local icon, use the icon's name directly. (ie. "${iconName}")`; } throw err; }