From 93c103078b90f083f2f4952a39c55c7747ae82ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 8 Apr 2023 13:21:46 -0300 Subject: [PATCH] Fix some errors reported by TypeScript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- js/global.d.ts | 17 ++++++++++++++++- js/src/codemirror/addon/lint/sql-lint.ts | 1 + js/src/designer/database.ts | 8 ++++---- js/src/modules/ajax-message.ts | 12 ++++++++---- js/src/modules/common.ts | 6 ++++++ js/src/modules/config.ts | 9 ++++++--- js/src/modules/console/config.ts | 10 +++++----- js/src/modules/cross_framing_protection.ts | 6 ++++++ js/src/modules/functions/formatDateTime.ts | 1 + js/src/modules/functions/ignorePhpErrors.ts | 6 ++++++ js/src/modules/functions/isStorageSupported.ts | 2 +- js/src/modules/keyhandler.ts | 2 +- js/src/modules/sql-highlight.ts | 1 + js/src/table/zoom_plot_jqplot.ts | 1 + js/src/transformations/image_upload.ts | 5 +++-- js/src/transformations/json.ts | 1 + js/src/transformations/xml.ts | 1 + 17 files changed, 68 insertions(+), 21 deletions(-) diff --git a/js/global.d.ts b/js/global.d.ts index 268bf50513..053fc5fd2b 100644 --- a/js/global.d.ts +++ b/js/global.d.ts @@ -29,10 +29,25 @@ interface JQuery { sortTable: (textSelector: string) => JQuery; filterByValue: (value: any) => any; + + uiTooltip(): JQuery; + uiTooltip(methodName: 'destroy'): void; + uiTooltip(methodName: 'disable'): void; + uiTooltip(methodName: 'enable'): void; + uiTooltip(methodName: 'open'): void; + uiTooltip(methodName: 'close'): void; + uiTooltip(methodName: 'widget'): JQuery; + uiTooltip(methodName: string): JQuery; + uiTooltip(options: JQueryUI.TooltipOptions): JQuery; + uiTooltip(optionLiteral: string, optionName: string): any; + uiTooltip(optionLiteral: string, options: JQueryUI.TooltipOptions): any; + uiTooltip(optionLiteral: string, optionName: string, optionValue: any): JQuery; } interface JQueryStatic { - timepicker: JQueryUI.Datepicker; + timepicker: any; + + tablesorter: any; jqplot: any; } diff --git a/js/src/codemirror/addon/lint/sql-lint.ts b/js/src/codemirror/addon/lint/sql-lint.ts index ab59056223..d02a840512 100644 --- a/js/src/codemirror/addon/lint/sql-lint.ts +++ b/js/src/codemirror/addon/lint/sql-lint.ts @@ -1,6 +1,7 @@ import $ from 'jquery'; import { CommonParams } from '../../../modules/common.ts'; +// @ts-ignore window.CodeMirror.sqlLint = function (text, updateLinting, options, cm) { // Skipping check if text box is empty. if (text.trim() === '') { diff --git a/js/src/designer/database.ts b/js/src/designer/database.ts index cfc0a1e099..ab958d8880 100644 --- a/js/src/designer/database.ts +++ b/js/src/designer/database.ts @@ -14,7 +14,7 @@ var designerTables = [ ]; var DesignerOfflineDB = (function () { - var designerDB = {}; + var designerDB: {[k: string]: any} = {}; /** * @type {IDBDatabase|null} @@ -61,8 +61,8 @@ var DesignerOfflineDB = (function () { var request = window.indexedDB.open('pma_designer', version); request.onupgradeneeded = function (e) { - var db = e.target.result; - e.target.transaction.onerror = designerDB.onerror; + var db = (e.target as IDBRequest).result; + (e.target as IDBRequest).transaction.onerror = designerDB.onerror; var t; for (t in designerTables) { @@ -80,7 +80,7 @@ var DesignerOfflineDB = (function () { }; request.onsuccess = function (e) { - datastore = e.target.result; + datastore = (e.target as IDBRequest).result; if (typeof callback === 'function') { callback(true); } diff --git a/js/src/modules/ajax-message.ts b/js/src/modules/ajax-message.ts index aeb827efcd..23ccc3a7c9 100644 --- a/js/src/modules/ajax-message.ts +++ b/js/src/modules/ajax-message.ts @@ -150,7 +150,7 @@ const ajaxShowMessage = function (message = null, timeout = null, type = null) { * * @param {JQuery} $thisMessageBox Element that holds the notification */ -const ajaxRemoveMessage = function ($thisMessageBox): void { +const ajaxRemoveMessage = function ($thisMessageBox: JQuery): void { if ($thisMessageBox !== undefined && $thisMessageBox instanceof $) { $thisMessageBox .stop(true, true) @@ -164,9 +164,13 @@ const ajaxRemoveMessage = function ($thisMessageBox): void { } }; -/** - * @return {number} - */ +declare global { + interface Window { + getAjaxMessageCount: () => number; + ajaxShowMessage: typeof ajaxShowMessage; + } +} + window.getAjaxMessageCount = () => ajaxMessageCount; window.ajaxShowMessage = ajaxShowMessage; diff --git a/js/src/modules/common.ts b/js/src/modules/common.ts index d4cc2bda6f..4867d89de6 100644 --- a/js/src/modules/common.ts +++ b/js/src/modules/common.ts @@ -97,6 +97,12 @@ const CommonParams = (function () { }; }()); +declare global { + interface Window { + CommonParams: typeof CommonParams; + } +} + window.CommonParams = CommonParams; export { CommonParams }; diff --git a/js/src/modules/config.ts b/js/src/modules/config.ts index 78a6feb398..aaf99cbf3f 100644 --- a/js/src/modules/config.ts +++ b/js/src/modules/config.ts @@ -139,7 +139,7 @@ function getFieldValue (field, fieldType) { * @return {object} */ function getAllValues () { - var $elements = $('fieldset input, fieldset select, fieldset textarea'); + var $elements = $('fieldset input, fieldset select, fieldset textarea') as JQuery; var values = {}; var type; var value; @@ -809,11 +809,11 @@ function on () { $form.find('input[type=submit]').prop('disabled', disabled); }).on('submit', function (e) { var $form = $(this); - if ($form.attr('name') === 'prefs_export' && $('#export_local_storage')[0].checked) { + if ($form.attr('name') === 'prefs_export' && ($('#export_local_storage') as JQuery)[0].checked) { e.preventDefault(); // use AJAX to read JSON settings and save them savePrefsToLocalStorage($form); - } else if ($form.attr('name') === 'prefs_import' && $('#import_local_storage')[0].checked) { + } else if ($form.attr('name') === 'prefs_import' && ($('#import_local_storage') as JQuery)[0].checked) { // set 'json' input and submit form $form.find('input[name=json]').val(window.localStorage.config); } @@ -844,6 +844,9 @@ const Config = { declare global { interface Window { + configInlineParams: any[] | undefined; + configScriptLoaded: boolean | undefined; + defaultValues: object; validators: typeof validators; Config: typeof Config; } diff --git a/js/src/modules/console/config.ts b/js/src/modules/console/config.ts index 707326665a..17b1f604d6 100644 --- a/js/src/modules/console/config.ts +++ b/js/src/modules/console/config.ts @@ -74,11 +74,11 @@ export const Config = { * Used for update console config */ update: function (): void { - this.set('AlwaysExpand', !! document.getElementById('consoleOptionsAlwaysExpandCheckbox').checked); - this.set('StartHistory', !! document.getElementById('consoleOptionsStartHistoryCheckbox').checked); - this.set('CurrentQuery', !! document.getElementById('consoleOptionsCurrentQueryCheckbox').checked); - this.set('EnterExecutes', !! document.getElementById('consoleOptionsEnterExecutesCheckbox').checked); - this.set('DarkTheme', !! document.getElementById('consoleOptionsDarkThemeCheckbox').checked); + this.set('AlwaysExpand', !! (document.getElementById('consoleOptionsAlwaysExpandCheckbox') as HTMLInputElement).checked); + this.set('StartHistory', !! (document.getElementById('consoleOptionsStartHistoryCheckbox') as HTMLInputElement).checked); + this.set('CurrentQuery', !! (document.getElementById('consoleOptionsCurrentQueryCheckbox') as HTMLInputElement).checked); + this.set('EnterExecutes', !! (document.getElementById('consoleOptionsEnterExecutesCheckbox') as HTMLInputElement).checked); + this.set('DarkTheme', !! (document.getElementById('consoleOptionsDarkThemeCheckbox') as HTMLInputElement).checked); /* Setting the dark theme of the console*/ const consoleContent = document.getElementById('pma_console').querySelector('.content'); if (this.DarkTheme) { diff --git a/js/src/modules/cross_framing_protection.ts b/js/src/modules/cross_framing_protection.ts index bdb578b576..830eacee84 100644 --- a/js/src/modules/cross_framing_protection.ts +++ b/js/src/modules/cross_framing_protection.ts @@ -1,3 +1,9 @@ +declare global { + interface Window { + allowThirdPartyFraming: boolean | string; + } +} + /** * Conditionally included if framing is not allowed. */ diff --git a/js/src/modules/functions/formatDateTime.ts b/js/src/modules/functions/formatDateTime.ts index 4c9823df5f..5edc024ac3 100644 --- a/js/src/modules/functions/formatDateTime.ts +++ b/js/src/modules/functions/formatDateTime.ts @@ -14,6 +14,7 @@ export default function formatDateTime (date, seconds = false) { timefmt = 'HH:mm:ss'; } + // @ts-ignore return result + ' ' + $.datepicker.formatTime( timefmt, { hour: date.getHours(), diff --git a/js/src/modules/functions/ignorePhpErrors.ts b/js/src/modules/functions/ignorePhpErrors.ts index 6296d89d92..5341aef883 100644 --- a/js/src/modules/functions/ignorePhpErrors.ts +++ b/js/src/modules/functions/ignorePhpErrors.ts @@ -30,6 +30,12 @@ function ignorePhpErrors (clearPrevErrors = undefined) { $pmaErrors.remove(); } +declare global { + interface Window { + ignorePhpErrors: typeof ignorePhpErrors; + } +} + window.ignorePhpErrors = ignorePhpErrors; export { ignorePhpErrors }; diff --git a/js/src/modules/functions/isStorageSupported.ts b/js/src/modules/functions/isStorageSupported.ts index 5bbf55df6d..df663251a2 100644 --- a/js/src/modules/functions/isStorageSupported.ts +++ b/js/src/modules/functions/isStorageSupported.ts @@ -8,7 +8,7 @@ import { ajaxShowMessage } from '../ajax-message.ts'; * * @return {boolean} */ -export default function isStorageSupported (type, warn = false) { +export default function isStorageSupported (type: 'localStorage' | 'sessionStorage', warn = false): boolean { try { window[type].setItem('PMATest', 'test'); // Check whether key-value pair was set successfully diff --git a/js/src/modules/keyhandler.ts b/js/src/modules/keyhandler.ts index d4dd59af0f..d56ba00b51 100644 --- a/js/src/modules/keyhandler.ts +++ b/js/src/modules/keyhandler.ts @@ -91,7 +91,7 @@ const onKeyDownArrowsHandler = function (event) { nO.focus(); if (nO.tagName !== 'SELECT') { - nO.select(); + (nO as HTMLInputElement).select(); } e.returnValue = false; diff --git a/js/src/modules/sql-highlight.ts b/js/src/modules/sql-highlight.ts index 7482bbadfc..eb085e7da0 100644 --- a/js/src/modules/sql-highlight.ts +++ b/js/src/modules/sql-highlight.ts @@ -465,6 +465,7 @@ export default function highlightSql ($base) { var $highlight = $('
'); $sql.append($highlight); if (typeof window.CodeMirror !== 'undefined') { + // @ts-ignore window.CodeMirror.runMode($sql.text(), 'text/x-mysql', $highlight[0]); $pre.hide(); $highlight.find('.cm-keyword').each(documentationKeyword); diff --git a/js/src/table/zoom_plot_jqplot.ts b/js/src/table/zoom_plot_jqplot.ts index ec08ee7cd4..757e7c0700 100644 --- a/js/src/table/zoom_plot_jqplot.ts +++ b/js/src/table/zoom_plot_jqplot.ts @@ -249,6 +249,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () { * Input form validation **/ $('#inputFormSubmitId').on('click', function () { + // @ts-ignore if ($('#tableid_0').get(0).selectedIndex === 0 || $('#tableid_1').get(0).selectedIndex === 0) { ajaxShowMessage(window.Messages.strInputNull); } else if (xLabel === yLabel) { diff --git a/js/src/transformations/image_upload.ts b/js/src/transformations/image_upload.ts index 3b6c5dfc37..4f503a8c54 100644 --- a/js/src/transformations/image_upload.ts +++ b/js/src/transformations/image_upload.ts @@ -11,14 +11,15 @@ AJAX.registerOnload('transformations/image_upload.js', function () { // Change thumbnail when image file is selected // through file upload dialog $('input.image-upload').on('change', function () { - if (this.files && this.files[0]) { + const fileInput = this as HTMLInputElement; + if (fileInput.files && fileInput.files[0]) { var reader = new FileReader(); var $input = $(this); reader.onload = function (e) { $input.prevAll('img').attr('src', e.target.result); }; - reader.readAsDataURL(this.files[0]); + reader.readAsDataURL(fileInput.files[0]); } }); }); diff --git a/js/src/transformations/json.ts b/js/src/transformations/json.ts index e38c1c7fd6..8c18dbe56b 100644 --- a/js/src/transformations/json.ts +++ b/js/src/transformations/json.ts @@ -13,6 +13,7 @@ AJAX.registerOnload('transformations/json.js', function () { if ($pre.is(':visible')) { var $highlight = $('
'); $json.append($highlight); + // @ts-ignore window.CodeMirror.runMode($json.text(), 'application/json', $highlight[0]); $pre.hide(); } diff --git a/js/src/transformations/xml.ts b/js/src/transformations/xml.ts index e7652656b4..c19ab11205 100644 --- a/js/src/transformations/xml.ts +++ b/js/src/transformations/xml.ts @@ -13,6 +13,7 @@ AJAX.registerOnload('transformations/xml.js', function () { if ($pre.is(':visible')) { var $highlight = $('
'); $json.append($highlight); + // @ts-ignore window.CodeMirror.runMode($json.text(), 'application/xml', $highlight[0]); $pre.hide(); }