From 3dbae89b2d582749ae8554edcd53f96c8cb10547 Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Thu, 9 Nov 2023 23:19:49 -0500 Subject: [PATCH] chore: add missing TS types --- lib/src/MultipleSelectInstance.ts | 18 +++++++++--------- lib/src/interfaces/interfaces.ts | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/src/MultipleSelectInstance.ts b/lib/src/MultipleSelectInstance.ts index d8d40ce5..a84ac752 100644 --- a/lib/src/MultipleSelectInstance.ts +++ b/lib/src/MultipleSelectInstance.ts @@ -283,7 +283,7 @@ export class MultipleSelectInstance { this.elm.childNodes.forEach((elm) => { const row = this.initRow(elm as HTMLOptionElement); if (row) { - data.push(row); + data.push(row as OptionRowData); } }); @@ -296,10 +296,10 @@ export class MultipleSelectInstance { } protected initRow(elm: HTMLOptionElement, groupDisabled?: boolean) { - const row: any = {}; + const row = {} as OptionRowData | OptGroupRowData; if (elm.tagName?.toLowerCase() === 'option') { row.type = 'option'; - row.text = this.options.textTemplate(elm); + (row as OptionRowData).text = this.options.textTemplate(elm); row.value = elm.value; row.visible = true; row.selected = Boolean(elm.selected); @@ -323,7 +323,7 @@ export class MultipleSelectInstance { if (elm.tagName?.toLowerCase() === 'optgroup') { row.type = 'optgroup'; - row.label = this.options.labelTemplate(elm); + (row as OptGroupRowData).label = this.options.labelTemplate(elm); row.visible = true; row.selected = Boolean(elm.selected); row.disabled = elm.disabled; @@ -333,7 +333,7 @@ export class MultipleSelectInstance { } elm.childNodes.forEach((childNode) => { - (row as OptGroupRowData).children.push(this.initRow(childNode as HTMLOptionElement, row.disabled)); + (row as OptGroupRowData).children.push(this.initRow(childNode as HTMLOptionElement, row.disabled) as OptionRowData); }); return row; @@ -1166,16 +1166,16 @@ export class MultipleSelectInstance { setSelects(values: any[], type = 'value', ignoreTrigger = false) { let hasChanged = false; - const _setSelects = (rows: any[]) => { + const _setSelects = (rows: Array) => { for (const row of rows) { let selected = false; if (type === 'text') { const divElm = document.createElement('div'); - this.applyAsTextOrHtmlWhenEnabled(divElm, row.text); + this.applyAsTextOrHtmlWhenEnabled(divElm, (row as OptionRowData).text); selected = values.includes(divElm.textContent?.trim() ?? ''); } else { selected = values.includes(row._value || row.value); - if (!selected && row.value === `${+row.value}`) { + if (!selected && row.value === `${+(row as OptionRowData).value}`) { selected = values.includes(+row.value); } } @@ -1261,7 +1261,7 @@ export class MultipleSelectInstance { protected _checkGroup(group: any, checked: boolean, ignoreUpdate?: boolean) { group.selected = checked; - group.children.forEach((row: any) => { + group.children.forEach((row: OptionRowData) => { if (row && !row.disabled && !row.divider && (ignoreUpdate || row.visible)) { row.selected = checked; } diff --git a/lib/src/interfaces/interfaces.ts b/lib/src/interfaces/interfaces.ts index 2a4da929..d06ed4af 100644 --- a/lib/src/interfaces/interfaces.ts +++ b/lib/src/interfaces/interfaces.ts @@ -18,6 +18,7 @@ export interface HtmlStruct { export interface OptionRowData { text: string; value: string | number | boolean; + html?: HTMLElement; classes?: string; divider?: string; disabled?: boolean; @@ -25,6 +26,7 @@ export interface OptionRowData { visible?: boolean | string; title?: string; type?: 'option' | 'optgroup'; + _data?: { divider?: string }; _key?: string; _value?: string | number | boolean; }