Преглед на файлове

ref: fix some ts-ignore usages

Sv443 преди 1 година
родител
ревизия
e03940ac2f
променени са 2 файла, в които са добавени 36 реда и са изтрити 26 реда
  1. 1 1
      src/dialogs/featHelp.ts
  2. 35 25
      src/menu/menu_old.ts

+ 1 - 1
src/dialogs/featHelp.ts

@@ -59,7 +59,7 @@ async function renderBody() {
   helpTextElem.id = "bytm-feat-help-dialog-text";
   helpTextElem.tabIndex = 0;
   // @ts-ignore
-  const helpText: string | undefined = featInfo[curFeatKey]?.helpText?.();
+  const helpText: string | undefined = featInfo[curFeatKey!]?.helpText?.();
   helpTextElem.textContent = helpText ?? t(`feature_helptext_${curFeatKey}`);
 
   contElem.appendChild(featDescElem);

+ 35 - 25
src/menu/menu_old.ts

@@ -306,8 +306,7 @@ async function addCfgMenu() {
     for(const featKey in featObj) {
       const ftInfo = featInfo[featKey as keyof typeof featureCfg] as FeatureInfo[keyof typeof featureCfg];
 
-      // @ts-ignore
-      if(!ftInfo || ftInfo.hidden === true)
+      if(!ftInfo || ("hidden" in ftInfo && ftInfo.hidden === true))
         continue;
 
       if(ftInfo.advanced && !featureCfg.advancedMode)
@@ -315,8 +314,7 @@ async function addCfgMenu() {
 
       const { type, default: ftDefault } = ftInfo;
 
-      // @ts-ignore
-      const step = ftInfo?.step ?? undefined;
+      const step = "step" in ftInfo ? ftInfo.step : undefined;
       const val = featureCfg[featKey as keyof typeof featureCfg];
 
       const initialVal = val ?? ftDefault ?? undefined;
@@ -329,10 +327,17 @@ async function addCfgMenu() {
         featLeftSideElem.classList.add("bytm-ftitem-leftside");
         if(getFeatures().advancedMode) {
           const defVal = fmtVal(ftDefault);
-          // @ts-ignore
-          const rel = ftInfo.reloadRequired === false ? "" : " (reload required)";
+          const extraTxts = [
+            `default: ${defVal.length === 0 ? "(undefined)" : defVal}`,
+          ];
+          "min" in ftInfo && extraTxts.push(`min: ${ftInfo.min}`);
+          "max" in ftInfo && extraTxts.push(`max: ${ftInfo.max}`);
+          "step" in ftInfo && extraTxts.push(`step: ${ftInfo.step}`);
+
+          const rel = "reloadRequired" in ftInfo && ftInfo.reloadRequired !== false ? " (reload required)" : "";
           const adv = ftInfo.advanced ? " (advanced feature)" : "";
-          featLeftSideElem.title = `${featKey}${rel}${adv} - default value: ${defVal.length === 0 ? "(undefined)" : defVal}`;
+
+          featLeftSideElem.title = `${featKey}${rel}${adv}${extraTxts.length > 0 ? `\n${extraTxts.join(" - ")}` : ""}`;
         }
 
         const textElem = document.createElement("span");
@@ -471,12 +476,10 @@ async function addCfgMenu() {
           if(inputType)
             inputElem.type = inputType;
 
-          // @ts-ignore
-          if(typeof ftInfo.min !== "undefined")// @ts-ignore
-            inputElem.min = ftInfo.min;
-          // @ts-ignore
-          if(typeof ftInfo.max !== "undefined") // @ts-ignore
-            inputElem.max = ftInfo.max;
+          if("min" in ftInfo && typeof ftInfo.min !== "undefined")
+            inputElem.min = String(ftInfo.min);
+          if("max" in ftInfo && typeof ftInfo.max !== "undefined")
+            inputElem.max = String(ftInfo.max);
 
           if(typeof initialVal !== "undefined")
             inputElem.value = String(initialVal);
@@ -490,11 +493,15 @@ async function addCfgMenu() {
           if(type === "toggle" && typeof initialVal !== "undefined")
             inputElem.checked = Boolean(initialVal);
 
-          // @ts-ignore
-          const unitTxt = (typeof ftInfo.unit === "string" ? ftInfo.unit : (
-            // @ts-ignore
-            typeof ftInfo.unit === "function" ? ftInfo.unit(Number(inputElem.value)) : ""
-          ));
+          const unitTxt = (
+            "unit" in ftInfo && typeof ftInfo.unit === "string"
+              ? ftInfo.unit
+              : (
+                "unit" in ftInfo && typeof ftInfo.unit === "function"
+                  ? ftInfo.unit(Number(inputElem.value))
+                  : ""
+              )
+          );
 
           let labelElem: HTMLLabelElement | undefined;
           let lastDisplayedVal: string | undefined;
@@ -641,18 +648,21 @@ async function addCfgMenu() {
       else
         ftElem.value = String(value);
 
-      // @ts-ignore
-      if(ftInfo.type === "text" && ftInfo.valueHidden)
+      if(ftInfo.type === "text" && "valueHidden" in ftInfo && ftInfo.valueHidden)
         ftElem.value = String(value).length === 0 ? "" : "•".repeat(16);
 
       if(!labelElem)
         continue;
 
-      // @ts-ignore
-      const unitTxt = " " + (typeof ftInfo.unit === "string" ? ftInfo.unit : (
-        // @ts-ignore
-        typeof ftInfo.unit === "function" ? ftInfo.unit(Number(ftElem.value)) : ""
-      ));
+      const unitTxt = (
+        "unit" in ftInfo && typeof ftInfo.unit === "string" 
+          ? ftInfo.unit
+          : (
+            "unit" in ftInfo && typeof ftInfo.unit === "function"
+              ? ftInfo.unit(Number(ftElem.value))
+              : ""
+          )
+      );
       if(ftInfo.type === "slider")
         labelElem.textContent = `${fmtVal(Number(value))}${unitTxt}`;
     }