Various TypeScript fixes detected using noImplicitAny
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 7 Jan 2021 13:57:53 +0000 (14:57 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 8 Jan 2021 09:33:00 +0000 (10:33 +0100)
15 files changed:
wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Editor.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Sync.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Add.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Data.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Dialog.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Format.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Screen.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Editor.ts

index 2e2ee7e7276f2d7c2c2ae9c6fed3e137a2727793..e5b2960f7fd483d170d7ceb590726a0586ce460c 100644 (file)
@@ -577,7 +577,7 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste
                     }
                     else {
                         element.dataset.value = time.toString();
-                        const format = isTimeOnly ? "formatTime" : "formatDate" + (isDateTime ? "Time" : "");
+                        const format = isTimeOnly ? "formatTime" : isDateTime ? "formatDateTime" : "formatDate";
                         value = DateUtil[format](date);
                     }
                 }
index ee3c9857a8b03d3a8703199feae0e4f5ae96deed..56aacdb5290ffb0f51991e06590ca7e977ddfac9 100644 (file)
@@ -94,7 +94,7 @@ define(["require", "exports", "tslib", "../../Dom/Util"], function (require, exp
      */
     function isBoundaryElement(element, parent, type) {
         let node = element;
-        while ((node = node[`${type}Sibling`])) {
+        while ((node = node[type])) {
             if (node.nodeType !== Node.TEXT_NODE || node.textContent.replace(/\u200B/, "") !== "") {
                 return false;
             }
@@ -215,8 +215,8 @@ define(["require", "exports", "tslib", "../../Dom/Util"], function (require, exp
             if (tmpElement === null && firstSelectedElement.parentElement === lastSelectedElement.parentElement) {
                 const parent = firstSelectedElement.parentElement;
                 if (parent.nodeName === "SPAN" && parent.style.getPropertyValue(property) !== "") {
-                    if (isBoundaryElement(firstSelectedElement, parent, "previous") &&
-                        isBoundaryElement(lastSelectedElement, parent, "next")) {
+                    if (isBoundaryElement(firstSelectedElement, parent, "previousSibling") &&
+                        isBoundaryElement(lastSelectedElement, parent, "nextSibling")) {
                         Util_1.default.unwrapChildNodes(parent);
                     }
                 }
index 040e604184620178a5116a8245913abeac338a74..838e9e7e19cbedd2d90e243893c3367ced3279f0 100644 (file)
@@ -177,7 +177,12 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ut
                         let label = reason.nextElementSibling;
                         const phrase = "wcf.user." + this.actionName + ".reason.description";
                         label.textContent = Language.get(phrase);
-                        window[label.textContent === phrase ? "elHide" : "elShow"](label);
+                        if (label.textContent === phrase) {
+                            Util_1.default.hide(label);
+                        }
+                        else {
+                            Util_1.default.show(label);
+                        }
                         label = document.getElementById("wcfUiUserEditorNeverExpires").nextElementSibling;
                         label.textContent = Language.get("wcf.user." + this.actionName + ".neverExpires");
                         label = content.querySelector('label[for="wcfUiUserEditorExpires"]');
index 516bb23a510aef410267da8a3a500301dc1144f3..ec7428845af3f4f5fe168dee011dfb2bd6bc5598 100644 (file)
@@ -37,7 +37,7 @@ class AcpUiDevtoolsProjectSync {
   private readonly projectId: number;
   private queue: PendingPip[] = [];
 
-  constructor(projectId) {
+  constructor(projectId: number) {
     this.projectId = projectId;
 
     const restrictedSync = document.getElementById("syncShowOnlyMatches") as HTMLInputElement;
index df7eb8961d19a354be56a48e07dbd73cc8dd3d00..cb0f857f2d655d5d78baa964d989503192bff8e3 100644 (file)
@@ -7,7 +7,7 @@
  * @module  WoltLabSuite/Core/Acp/Ui/Page/Add
  */
 
-import { DialogCallbackObject } from "../../../Ui/Dialog/Data";
+import { DialogCallbackObject, DialogCallbackSetup } from "../../../Ui/Dialog/Data";
 import * as Language from "../../../Language";
 import UiDialog from "../../../Ui/Dialog";
 
@@ -35,7 +35,7 @@ class AcpUiPageAdd implements DialogCallbackObject {
     UiDialog.open(this);
   }
 
-  _dialogSetup() {
+  _dialogSetup(): ReturnType<DialogCallbackSetup> {
     return {
       id: "pageAddDialog",
       options: {
index 2abc9b64bfc3aa48c60398496530e9db706c77fc..a8be9494fd1f4fe0f0c4962202dbd95acc8bb0a3 100644 (file)
@@ -698,7 +698,7 @@ const DatePicker = {
             value = "";
           } else {
             element.dataset.value = time.toString();
-            const format = isTimeOnly ? "formatTime" : "formatDate" + (isDateTime ? "Time" : "");
+            const format = isTimeOnly ? "formatTime" : isDateTime ? "formatDateTime" : "formatDate";
             value = DateUtil[format](date);
           }
         }
index 8404075449308a50230e3fb469baf56e9f7aeb06..6d19d480d9d09fc30b43ca5e5035dab0cf05bcf2 100644 (file)
@@ -15,6 +15,8 @@ const enum Type {
   TagName,
 }
 
+type SiblingType = "nextElementSibling" | "previousElementSibling";
+
 const _test = new Map<Type, (...args: any[]) => boolean>([
   [Type.None, () => true],
   [Type.Selector, (element: Element, selector: string) => element.matches(selector)],
@@ -58,7 +60,7 @@ function _getParent(element: Element, type: Type, value: string, untilElement?:
   return null;
 }
 
-function _getSibling(element: Element, siblingType: string, type: Type, value: string): Element | null {
+function _getSibling(element: Element, siblingType: SiblingType, type: Type, value: string): Element | null {
   if (!(element instanceof Element)) {
     throw new TypeError("Expected a valid element as first argument.");
   }
index e2fdaea295e2d8519b2366bb5187367092728b2c..e84e1d2a7e182710f48516460dfaee8175cf42d7 100644 (file)
@@ -4,6 +4,11 @@ interface InternalFormBuilderData {
   [key: string]: any;
 }
 
+export interface AjaxResponseReturnValues {
+  dialog: string;
+  formId: string;
+}
+
 export type FormBuilderData = InternalFormBuilderData | Promise<InternalFormBuilderData>;
 
 export interface FormBuilderDialogOptions {
@@ -13,9 +18,9 @@ export interface FormBuilderDialogOptions {
   closeCallback: () => void;
   destroyOnClose: boolean;
   dialog: DialogOptions;
-  onSubmit: (FormBuilderData, HTMLButtonElement) => void;
+  onSubmit: (formData: FormBuilderData, submitButton: HTMLButtonElement) => void;
   submitActionName?: string;
-  successCallback: (AjaxResponseReturnValues) => void;
+  successCallback: (returnValues: AjaxResponseReturnValues) => void;
   usesDboAction: boolean;
 }
 
index 50a292df5c7847c17fde10a20202f3c15aa6f338..f37e78790d07a891fef06e638a5428305fef42b5 100644 (file)
@@ -14,12 +14,7 @@ import { DialogCallbackObject, DialogCallbackSetup, DialogData } from "../../Ui/
 import * as Ajax from "../../Ajax";
 import { AjaxCallbackObject, AjaxCallbackSetup, DatabaseObjectActionResponse, RequestOptions } from "../../Ajax/Data";
 import * as FormBuilderManager from "./Manager";
-import { FormBuilderData, FormBuilderDialogOptions } from "./Data";
-
-interface AjaxResponseReturnValues {
-  dialog: string;
-  formId: string;
-}
+import { AjaxResponseReturnValues, FormBuilderData, FormBuilderDialogOptions } from "./Data";
 
 interface AjaxResponse extends DatabaseObjectActionResponse {
   returnValues: AjaxResponseReturnValues;
index ae8a4498f8ae481566140a01697aafde72ebf81b..c41251b6630e97550c30c83cc896dd63373606de 100644 (file)
@@ -34,7 +34,7 @@ interface AjaxResponse extends DatabaseObjectActionResponse {
 }
 
 interface ValidationApi {
-  throwError: (HTMLElement, string) => void;
+  throwError: (container: HTMLElement, message: string) => void;
 }
 
 interface ValidationData {
@@ -342,7 +342,7 @@ class UiPollEditor {
       const maxVotes = ~~this.maxVotesField.value;
 
       if (maxVotes && maxVotes > nonEmptyOptionCount) {
-        data.api.throwError(this.maxVotesField.parentElement, Language.get("wcf.poll.maxVotes.error.invalid"));
+        data.api.throwError(this.maxVotesField.parentElement!, Language.get("wcf.poll.maxVotes.error.invalid"));
         data.valid = false;
       } else {
         EventHandler.fire("com.woltlab.wcf.poll.editor", "validate", {
index b3837569cd332718b4dac93272cefb7c7dcb0949..324531f5d1f8efbec54b9de21b1f3f5b06c3ef21 100644 (file)
@@ -192,7 +192,7 @@ class UiRedactorCode implements DialogCallbackObject {
           let highlighters = `<option value="">${Language.get("wcf.editor.code.highlighter.detect")}</option>
             <option value="plain">${Language.get("wcf.editor.code.highlighter.plain")}</option>`;
 
-          const values: Highlighter[] = this._editor.opts.woltlab.highlighters.map((highlighter) => {
+          const values: Highlighter[] = this._editor.opts.woltlab.highlighters.map((highlighter: string) => {
             return [highlighter, PrismMeta[highlighter].title];
           });
 
index 88041bfa53e1b533e38c0f1e4dc5a479e48c6ca6..d4891a498fc52a10ae5ca3dc6921796c7f9a9fe7 100644 (file)
@@ -109,9 +109,13 @@ function getLastMatchingParent(
  * of its parent, ignoring empty text nodes appearing between the
  * element and the boundary.
  */
-function isBoundaryElement(element: HTMLElement, parent: HTMLElement, type: string): boolean {
-  let node = element;
-  while ((node = node[`${type}Sibling`])) {
+function isBoundaryElement(
+  element: HTMLElement,
+  parent: HTMLElement,
+  type: "previousSibling" | "nextSibling",
+): boolean {
+  let node: Node | null = element;
+  while ((node = node[type])) {
     if (node.nodeType !== Node.TEXT_NODE || node.textContent!.replace(/\u200B/, "") !== "") {
       return false;
     }
@@ -262,8 +266,8 @@ export function format(editorElement: HTMLElement, property: string, value: stri
       const parent = firstSelectedElement.parentElement!;
       if (parent.nodeName === "SPAN" && parent.style.getPropertyValue(property) !== "") {
         if (
-          isBoundaryElement(firstSelectedElement, parent, "previous") &&
-          isBoundaryElement(lastSelectedElement, parent, "next")
+          isBoundaryElement(firstSelectedElement, parent, "previousSibling") &&
+          isBoundaryElement(lastSelectedElement, parent, "nextSibling")
         ) {
           DomUtil.unwrapChildNodes(parent);
         }
index fb0ff601c4dd077b6a7d251e44f9412d4183c510..9e330b895c7d16880aa4c00c4d130c1b51ac5ac3 100644 (file)
@@ -14,7 +14,7 @@ import * as Environment from "../Environment";
 const _mql = new Map<string, MediaQueryData>();
 
 let _scrollDisableCounter = 0;
-let _scrollOffsetFrom: string;
+let _scrollOffsetFrom: "body" | "documentElement";
 let _scrollTop = 0;
 let _pageOverlayCounter = 0;
 
index 87dc742e24de5235010b0a54df5f63be91c53981..e766fa51f2ada28c6b4e21dede4a0aaba14bde77 100644 (file)
@@ -131,7 +131,7 @@ function selectErroneousTabs(): void {
   });
 }
 
-function scrollEnable(isSetup) {
+function scrollEnable(isSetup: boolean) {
   _enableTabScroll = true;
   _tabMenus.forEach((tabMenu) => {
     const activeTab = tabMenu.getActiveTab();
@@ -147,7 +147,14 @@ function scrollDisable() {
   _enableTabScroll = false;
 }
 
-function scrollMenu(list, left, scrollLeft, scrollWidth, width, paddingRight) {
+function scrollMenu(
+  list: HTMLElement,
+  left: number,
+  scrollLeft: number,
+  scrollWidth: number,
+  width: number,
+  paddingRight: boolean,
+) {
   // allow some padding to indicate overflow
   if (paddingRight) {
     left -= 15;
@@ -170,7 +177,7 @@ function scrollMenu(list, left, scrollLeft, scrollWidth, width, paddingRight) {
 
   // new value is larger, we're scrolling towards the end
   if (scrollLeft < left) {
-    list.firstElementChild.style.setProperty("margin-left", `${scrollLeft - left}px`, "");
+    (list.firstElementChild as HTMLElement).style.setProperty("margin-left", `${scrollLeft - left}px`, "");
   } else {
     // new value is smaller, we're scrolling towards the start
     list.style.setProperty("padding-left", `${scrollLeft - left}px`, "");
@@ -178,7 +185,7 @@ function scrollMenu(list, left, scrollLeft, scrollWidth, width, paddingRight) {
 
   setTimeout(() => {
     list.classList.remove("enableAnimation");
-    list.firstElementChild.style.removeProperty("margin-left");
+    (list.firstElementChild as HTMLElement).style.removeProperty("margin-left");
     list.style.removeProperty("padding-left");
     list.scrollLeft = left;
   }, 300);
index cf0613302e2fb9af43c313f577125aad077bc80f..d84508368a4605bccc9974fb9e55496c2a8e1898 100644 (file)
@@ -213,7 +213,11 @@ class UserEditor implements AjaxCallbackObject, DialogCallbackObject {
           let label = reason.nextElementSibling as HTMLElement;
           const phrase = "wcf.user." + this.actionName + ".reason.description";
           label.textContent = Language.get(phrase);
-          window[label.textContent === phrase ? "elHide" : "elShow"](label);
+          if (label.textContent === phrase) {
+            DomUtil.hide(label);
+          } else {
+            DomUtil.show(label);
+          }
 
           label = document.getElementById("wcfUiUserEditorNeverExpires")!.nextElementSibling as HTMLElement;
           label.textContent = Language.get("wcf.user." + this.actionName + ".neverExpires");