From 0c27a287b6a9e1062130dc29a03372e7a0fd8603 Mon Sep 17 00:00:00 2001 From: Will Eastcott Date: Thu, 19 Jan 2023 21:30:08 +0000 Subject: [PATCH 1/4] Various typing improvements --- src/components/ColorPicker/index.ts | 2 -- src/components/Container/index.ts | 4 ++-- src/components/Label/index.ts | 4 ++-- src/components/NumericInput/index.ts | 5 ++--- src/components/SelectInput/index.ts | 4 ++-- src/components/TextInput/index.ts | 7 ++++--- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/ColorPicker/index.ts b/src/components/ColorPicker/index.ts index ddb4719b..e2a4291c 100644 --- a/src/components/ColorPicker/index.ts +++ b/src/components/ColorPicker/index.ts @@ -558,7 +558,6 @@ class ColorPicker extends Element implements IBindable { this._changing = true; - // @ts-ignore const hex = this._fieldHex.value.trim().toLowerCase(); if (/^([0-9a-f]{2}){3,4}$/.test(hex)) { for (let i = 0; i < this._channelsNumber; i++) { @@ -676,7 +675,6 @@ class ColorPicker extends Element implements IBindable { } if (different) { - // @ts-ignore this.value = null; this.dom.classList.add(CLASS_MULTIPLE_VALUES); } else { diff --git a/src/components/Container/index.ts b/src/components/Container/index.ts index 4fd27482..76ba25d0 100644 --- a/src/components/Container/index.ts +++ b/src/components/Container/index.ts @@ -626,9 +626,9 @@ class Container extends Element { * @returns The recursively appended element node. * */ - protected _buildDomNode(node: { [x: string]: any; root?: any; children?: any; }) { + protected _buildDomNode(node: { [x: string]: any; root?: any; children?: any; }): Container { const keys = Object.keys(node); - let rootNode: { append: (arg0: any) => void; }; + let rootNode: Container; if (keys.includes('root')) { rootNode = this._buildDomNode(node.root); node.children.forEach((childNode: any) => { diff --git a/src/components/Label/index.ts b/src/components/Label/index.ts index c51b32bd..486f577d 100644 --- a/src/components/Label/index.ts +++ b/src/components/Label/index.ts @@ -10,7 +10,7 @@ export interface LabelArgs extends ElementArgs, IBindableArgs, IPlaceholderArgs, /** * Sets the text of the Label. Defaults to ''. */ - text?: string | number, + text?: string, /** * If `true`, the {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML innerHTML} property will be * used to set the text. Otherwise, {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent textContent} @@ -32,7 +32,7 @@ export interface LabelArgs extends ElementArgs, IBindableArgs, IPlaceholderArgs, /** * Sets the value of the Label. Defaults to ''. */ - value?: any, + value?: string } /** diff --git a/src/components/NumericInput/index.ts b/src/components/NumericInput/index.ts index bcc3a1e0..78f6e413 100644 --- a/src/components/NumericInput/index.ts +++ b/src/components/NumericInput/index.ts @@ -59,7 +59,7 @@ class NumericInput extends InputElement { protected _stepPrecision: number; - protected _oldValue: any; + protected _oldValue: number; protected _historyCombine: boolean; @@ -186,7 +186,7 @@ class NumericInput extends InputElement { } }; - protected _onInputChange(evt: any) { + protected _onInputChange(evt: Event) { // get the content of the input, normalize it and set it as the current value this.value = this._normalizeValue(this._domInput.value); } @@ -309,7 +309,6 @@ class NumericInput extends InputElement { get value() : number { const val = this._domInput.value; - // @ts-ignore return val !== '' ? parseFloat(val) : null; } diff --git a/src/components/SelectInput/index.ts b/src/components/SelectInput/index.ts index 718c9c06..dfb4c42a 100644 --- a/src/components/SelectInput/index.ts +++ b/src/components/SelectInput/index.ts @@ -130,7 +130,7 @@ class SelectInput extends Element implements IBindable, IFocusable { protected _value: any; - protected _createLabelContainer: any; + protected _createLabelContainer: Container; protected _options: any; @@ -571,7 +571,7 @@ class SelectInput extends Element implements IBindable, IFocusable { return container; } - protected _removeTag(tagElement: any, value: string) { + protected _removeTag(tagElement: Container, value: string) { tagElement.destroy(); const label = this._valueToLabel[value]; diff --git a/src/components/TextInput/index.ts b/src/components/TextInput/index.ts index 9d15f348..f0e79e2a 100644 --- a/src/components/TextInput/index.ts +++ b/src/components/TextInput/index.ts @@ -9,8 +9,9 @@ const CLASS_TEXT_INPUT = 'pcui-text-input'; */ export interface TextInputArgs extends InputElementArgs, IBindableArgs, IPlaceholderArgs { /** - * A function that validates the value that is entered into the input and returns `true` if it is valid or `false` otherwise. - * If `false` then the input will be set in an error state and the value will not propagate to the binding. + * A function that validates the value that is entered into the input and returns `true` if it + * is valid or `false` otherwise. If `false` then the input will be set in an error state and + * the value will not propagate to the binding. */ onValidate?: (value: string) => boolean, } @@ -19,7 +20,7 @@ export interface TextInputArgs extends InputElementArgs, IBindableArgs, IPlaceho * The TextInput is an input element of type text. */ class TextInput extends InputElement { - protected _onValidate: any; + protected _onValidate: (value: string) => boolean; constructor(args: Readonly = {}) { super(args); From 48a812d816ef7a7a7af3f1eb6fd2595c0909cd0e Mon Sep 17 00:00:00 2001 From: Will Eastcott Date: Fri, 20 Jan 2023 07:40:12 +0000 Subject: [PATCH 2/4] Type click fn --- src/components/GridView/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/GridView/index.ts b/src/components/GridView/index.ts index 6b090f76..c186e2f2 100644 --- a/src/components/GridView/index.ts +++ b/src/components/GridView/index.ts @@ -48,7 +48,7 @@ class GridView extends Container { protected _selected: GridViewItem[]; - protected _clickFn: any; + protected _clickFn: (evt: MouseEvent, item: GridViewItem) => void; constructor(args: Readonly = {}) { super(args); From bc556cc3e0a85816251874a29e9ec6546f2b05d3 Mon Sep 17 00:00:00 2001 From: Will Eastcott Date: Fri, 20 Jan 2023 07:42:26 +0000 Subject: [PATCH 3/4] Move function declaration --- src/components/GridView/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/GridView/index.ts b/src/components/GridView/index.ts index c186e2f2..2ac9dd34 100644 --- a/src/components/GridView/index.ts +++ b/src/components/GridView/index.ts @@ -36,6 +36,8 @@ export interface GridViewArgs extends ContainerArgs { class GridView extends Container { protected _vertical: boolean; + protected _clickFn: (evt: MouseEvent, item: GridViewItem) => void; + protected _filterFn: (item: GridViewItem) => boolean; protected _filterAnimationFrame: number; @@ -48,8 +50,6 @@ class GridView extends Container { protected _selected: GridViewItem[]; - protected _clickFn: (evt: MouseEvent, item: GridViewItem) => void; - constructor(args: Readonly = {}) { super(args); From e5d902c82daab3975ee18383a94ec3e450a5b91f Mon Sep 17 00:00:00 2001 From: Will Eastcott Date: Fri, 20 Jan 2023 07:47:54 +0000 Subject: [PATCH 4/4] Type context menu function --- src/components/TreeView/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/TreeView/index.ts b/src/components/TreeView/index.ts index 5b7bd713..e937b57a 100644 --- a/src/components/TreeView/index.ts +++ b/src/components/TreeView/index.ts @@ -36,7 +36,7 @@ export interface TreeViewArgs extends ContainerArgs { /** * A function to be called when we right click on a {@link TreeViewItem}. */ - onContextMenu?: any, + onContextMenu?: (evt: MouseEvent, item: TreeViewItem) => void, /** * A function to be called when we try to reparent tree items. If a function is provided then the * tree items will not be reparented by the {@link TreeView} but instead will rely on the function to @@ -166,7 +166,7 @@ class TreeView extends Container { protected _dragScrollElement: any; - protected _onContextMenu: any; + protected _onContextMenu: (evt: MouseEvent, item: TreeViewItem) => void; protected _onReparentFn: any;