From 66bbb469018942dbbc41975683ff907529d50ec9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 30 Oct 2020 12:11:33 +0100 Subject: [PATCH] Add parameter types where possible --- .../files/ts/WoltLabSuite/Core/Dictionary.ts | 12 ++++++------ .../files/ts/WoltLabSuite/Core/Dom/Traverse.ts | 2 +- .../files/ts/WoltLabSuite/Core/Ui/Acl/Simple.ts | 15 +++++++++------ .../ts/WoltLabSuite/Core/Ui/Page/Search/Input.ts | 2 +- .../files/ts/WoltLabSuite/Core/Ui/TabMenu.ts | 2 +- .../ts/WoltLabSuite/Core/Ui/TabMenu/Simple.ts | 2 +- .../ts/WoltLabSuite/Core/Ui/User/Search/Input.ts | 7 ++++++- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts index be316efbe8..52f542aea1 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts @@ -14,13 +14,13 @@ */ /** @deprecated 5.4 Use a `Map` instead. */ -class Dictionary { - private readonly _dictionary = new Map(); +class Dictionary { + private readonly _dictionary = new Map(); /** * Sets a new key with given value, will overwrite an existing key. */ - set(key: number | string, value: any): void { + set(key: number | string, value: T): void { this._dictionary.set(key.toString(), value); } @@ -49,7 +49,7 @@ class Dictionary { * Iterates over the dictionary keys and values, callback function should expect the * value as first parameter and the key name second. */ - forEach(callback: (value: any, key: string) => void): void { + forEach(callback: (value: T, key: number | string) => void): void { if (typeof callback !== "function") { throw new TypeError("forEach() expects a callback as first parameter."); } @@ -60,7 +60,7 @@ class Dictionary { /** * Merges one or more Dictionary instances into this one. */ - merge(...dictionaries: Dictionary[]): void { + merge(...dictionaries: Dictionary[]): void { for (let i = 0, length = dictionaries.length; i < length; i++) { const dictionary = dictionaries[i]; @@ -83,7 +83,7 @@ class Dictionary { * All properties that are owned by the object will be added * as keys to the resulting Dictionary. */ - static fromObject(object: object): Dictionary { + static fromObject(object: object): Dictionary { const result = new Dictionary(); for (const key in object) { diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts index 8c76750f51..a44e689f87 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Traverse.ts @@ -96,7 +96,7 @@ export function childByTag(element: Element, tagName: string): Element | null { /** * Examines child elements and returns all children matching the given selector. */ -export function childrenBySel(element, selector: string): Element[] { +export function childrenBySel(element: Element, selector: string): Element[] { return _getChildren(element, Type.Selector, selector); } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Acl/Simple.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Acl/Simple.ts index 1005e77482..ece28082bd 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Acl/Simple.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Acl/Simple.ts @@ -35,12 +35,15 @@ class UiAclSimple { excludedSearchValues.push(label.textContent!); }); - this.searchInput = new UiUserSearchInput(document.getElementById(this.prefix + "aclSearchInput"), { - callbackSelect: this.select.bind(this), - includeUserGroups: true, - excludedSearchValues: excludedSearchValues, - preventSubmit: true, - }); + this.searchInput = new UiUserSearchInput( + document.getElementById(this.prefix + "aclSearchInput") as HTMLInputElement, + { + callbackSelect: this.select.bind(this), + includeUserGroups: true, + excludedSearchValues: excludedSearchValues, + preventSubmit: true, + } + ); this.aclListContainer = document.getElementById(this.prefix + "aclListContainer")!; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Page/Search/Input.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Page/Search/Input.ts index f027992a8a..baefcd8f53 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Page/Search/Input.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Page/Search/Input.ts @@ -58,7 +58,7 @@ class UiPageSearchInput extends UiSearchInput { return data; } - _ajaxSuccess(data): void { + _ajaxSuccess(data: DatabaseObjectActionResponse): void { this.callbackSuccess(data); } } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts index 50ce3a3b10..ffd3b1ef63 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu.ts @@ -23,7 +23,7 @@ const _tabMenus = new Map(); * Initializes available tab menus. */ function init() { - document.querySelectorAll(".tabMenuContainer:not(.staticTabMenuContainer)").forEach((container) => { + document.querySelectorAll(".tabMenuContainer:not(.staticTabMenuContainer)").forEach((container: HTMLElement) => { const containerId = DomUtil.identify(container); if (_tabMenus.has(containerId)) { return; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu/Simple.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu/Simple.ts index 0f5230084f..ffe29675a5 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu/Simple.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/TabMenu/Simple.ts @@ -19,7 +19,7 @@ class TabMenuSimple { private store: HTMLInputElement | null = null; private readonly tabs = new Map(); - constructor(container) { + constructor(container: HTMLElement) { this.container = container; } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.ts index 1ac8818fcd..8385d1dbe4 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Search/Input.ts @@ -9,10 +9,11 @@ */ import * as Core from "../../../Core"; +import { SearchInputOptions } from "../../Search/Data"; import UiSearchInput from "../../Search/Input"; class UiUserSearchInput extends UiSearchInput { - constructor(element, options) { + constructor(element: HTMLInputElement, options: UserSearchInputOptions) { const includeUserGroups = Core.isPlainObject(options) && options.includeUserGroups === true; options = Core.extend( @@ -56,3 +57,7 @@ interface UserListItemData extends FirstArgument