From: Tim Düsterhus Date: Thu, 7 Jan 2021 13:57:53 +0000 (+0100) Subject: Various TypeScript fixes detected using noImplicitAny X-Git-Tag: 5.4.0_Alpha_1~467^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=96a9c6ac40f154f97ec83b5ce6403f5bdb39cd9d;p=GitHub%2FWoltLab%2FWCF.git Various TypeScript fixes detected using noImplicitAny --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js index 2e2ee7e727..e5b2960f7f 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js @@ -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); } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js index ee3c9857a8..56aacdb529 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js @@ -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); } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Editor.js index 040e604184..838e9e7e19 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Editor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Editor.js @@ -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"]'); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Sync.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Sync.ts index 516bb23a51..ec7428845a 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Sync.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Devtools/Project/Sync.ts @@ -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; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Add.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Add.ts index df7eb8961d..cb0f857f2d 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Add.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Add.ts @@ -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 { return { id: "pageAddDialog", options: { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts index 2abc9b64bf..a8be9494fd 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Date/Picker.ts @@ -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); } } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts index 8404075449..6d19d480d9 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts @@ -15,6 +15,8 @@ const enum Type { TagName, } +type SiblingType = "nextElementSibling" | "previousElementSibling"; + const _test = new Map 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."); } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Data.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Data.ts index e2fdaea295..e84e1d2a7e 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Data.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Data.ts @@ -4,6 +4,11 @@ interface InternalFormBuilderData { [key: string]: any; } +export interface AjaxResponseReturnValues { + dialog: string; + formId: string; +} + export type FormBuilderData = InternalFormBuilderData | Promise; 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; } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Dialog.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Dialog.ts index 50a292df5c..f37e78790d 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Dialog.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Dialog.ts @@ -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; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts index ae8a4498f8..c41251b663 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts @@ -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", { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts index b3837569cd..324531f5d1 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Code.ts @@ -192,7 +192,7 @@ class UiRedactorCode implements DialogCallbackObject { let highlighters = ` `; - 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]; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Format.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Format.ts index 88041bfa53..d4891a498f 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Format.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Format.ts @@ -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); } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Screen.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Screen.ts index fb0ff601c4..9e330b895c 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Screen.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Screen.ts @@ -14,7 +14,7 @@ import * as Environment from "../Environment"; const _mql = new Map(); let _scrollDisableCounter = 0; -let _scrollOffsetFrom: string; +let _scrollOffsetFrom: "body" | "documentElement"; let _scrollTop = 0; let _pageOverlayCounter = 0; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts index 87dc742e24..e766fa51f2 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts @@ -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); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Editor.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Editor.ts index cf0613302e..d84508368a 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Editor.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Editor.ts @@ -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");