From 5e776b3cb810f0de4237d09b2094893ddc67d204 Mon Sep 17 00:00:00 2001 From: filipKovachev Date: Mon, 2 Dec 2024 15:31:50 +0200 Subject: [PATCH] resolve TS error --- .../src/components/Header.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/ecommerce-jewellery-store/src/components/Header.tsx b/examples/ecommerce-jewellery-store/src/components/Header.tsx index 6fed5c85..a9affc38 100644 --- a/examples/ecommerce-jewellery-store/src/components/Header.tsx +++ b/examples/ecommerce-jewellery-store/src/components/Header.tsx @@ -45,7 +45,7 @@ const Header: React.FC = () => { }; const handleMenuSelect = (event: MenuSelectEvent) => { - const selectedItem: CustomMenuItemModel = event.item; + const selectedItem = event.item as CustomMenuItemModel; if (selectedItem.page) { navigate(selectedItem.page); @@ -62,15 +62,17 @@ const Header: React.FC = () => { }; const handleLanguageMenuSelect = (event: MenuSelectEvent) => { - const selectedLanguage = event.item.id?.replace("lang-", ""); - if (selectedLanguage) { + const selectedItem = event.item as CustomMenuItemModel; + const selectedLanguage = selectedItem.id?.replace("lang-", "") as "en" | "fr" | "es"; + + if (["en", "fr", "es"].includes(selectedLanguage)) { setLanguage(selectedLanguage); console.log(`Language changed to: ${selectedLanguage}`); } else { console.error(`Invalid language selected: ${selectedLanguage}`); } }; - + const translatedItems = items.map((item) => ({ ...item, text: t[`menu${item.text}`] || item.text,