From c575d62d5aa84c4e6e9e3fccff8316bf20287895 Mon Sep 17 00:00:00 2001 From: xoldyckk Date: Fri, 31 Mar 2023 21:21:37 +0530 Subject: [PATCH] ts: Migrate header.js to typescript. Added strict if block check to make sure `labelID` is defined at runtime. --- web/src/portico/{header.js => header.ts} | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) rename web/src/portico/{header.js => header.ts} (88%) diff --git a/web/src/portico/header.js b/web/src/portico/header.ts similarity index 88% rename from web/src/portico/header.js rename to web/src/portico/header.ts index 6ca2b99af2..c7ecf0db67 100644 --- a/web/src/portico/header.js +++ b/web/src/portico/header.ts @@ -1,7 +1,9 @@ import $ from "jquery"; $(() => { - function on_tab_menu_selection_change(event) { + function on_tab_menu_selection_change( + event?: JQuery.ChangeEvent | JQuery.ClickEvent, + ): void { // Pass event to open menu and if it is undefined, we close the menu. if (!event) { $("#top-menu-submenu-backdrop").css("height", "0px"); @@ -15,7 +17,7 @@ $(() => { } } - function on_top_menu_tab_unselect_click() { + function on_top_menu_tab_unselect_click(): void { // Close the menu. $("#top-menu-tab-close").prop("checked", true); on_tab_menu_selection_change(); @@ -64,6 +66,9 @@ $(() => { e.preventDefault(); e.stopPropagation(); const labelID = $(e.currentTarget).attr("for"); + if (labelID === undefined) { + throw new Error("Current target of this event must have for attribute defined."); + } $(`#${CSS.escape(labelID)}`).trigger("click"); } });