From 675c288811364ac08146c7e8038de23d5584c29d Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 21 Nov 2024 14:57:42 +0100 Subject: [PATCH] Fix some typescript issues (#32586) Fixes around 30 or so typescript errors. No runtime changes. --- .eslintrc.yaml | 2 +- web_src/js/features/autofocus-end.ts | 2 +- web_src/js/features/captcha.ts | 2 ++ web_src/js/features/citation.ts | 10 ++++---- web_src/js/features/clipboard.ts | 4 +-- web_src/js/features/codeeditor.ts | 16 ++++++------ web_src/js/features/colorpicker.ts | 12 ++++----- web_src/js/features/common-button.ts | 10 ++++---- web_src/js/globals.d.ts | 4 +++ web_src/js/markup/math.ts | 2 +- web_src/js/modules/dirauto.ts | 2 +- web_src/js/modules/fetch.ts | 2 +- web_src/js/modules/fomantic.ts | 2 +- web_src/js/modules/fomantic/api.ts | 5 ++-- web_src/js/modules/fomantic/base.ts | 2 +- web_src/js/modules/fomantic/dimmer.ts | 2 +- web_src/js/modules/fomantic/dropdown.ts | 31 ++++++++++++----------- web_src/js/modules/fomantic/modal.ts | 5 ++-- web_src/js/modules/fomantic/transition.ts | 4 +-- web_src/js/modules/sortable.ts | 9 ++++--- web_src/js/modules/tippy.ts | 25 +++++++++--------- web_src/js/modules/worker.ts | 2 +- web_src/js/types.ts | 5 ++++ web_src/js/utils/match.ts | 2 +- 24 files changed, 89 insertions(+), 73 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 081e4a2db4b17..88ae98db8df40 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -642,7 +642,7 @@ rules: no-this-before-super: [2] no-throw-literal: [2] no-undef-init: [2] - no-undef: [2, {typeof: true}] + no-undef: [2, {typeof: true}] # TODO: disable this rule after tsc passes no-undefined: [0] no-underscore-dangle: [0] no-unexpected-multiline: [2] diff --git a/web_src/js/features/autofocus-end.ts b/web_src/js/features/autofocus-end.ts index da71ce9536d62..53e475b543def 100644 --- a/web_src/js/features/autofocus-end.ts +++ b/web_src/js/features/autofocus-end.ts @@ -1,5 +1,5 @@ export function initAutoFocusEnd() { - for (const el of document.querySelectorAll('.js-autofocus-end')) { + for (const el of document.querySelectorAll('.js-autofocus-end')) { el.focus(); // expects only one such element on one page. If there are many, then the last one gets the focus. el.setSelectionRange(el.value.length, el.value.length); } diff --git a/web_src/js/features/captcha.ts b/web_src/js/features/captcha.ts index 23dbae374065b..69b4aa6852fca 100644 --- a/web_src/js/features/captcha.ts +++ b/web_src/js/features/captcha.ts @@ -35,9 +35,11 @@ export async function initCaptcha() { } case 'm-captcha': { const {default: mCaptcha} = await import(/* webpackChunkName: "mcaptcha-vanilla-glue" */'@mcaptcha/vanilla-glue'); + // @ts-expect-error mCaptcha.INPUT_NAME = 'm-captcha-response'; const instanceURL = captchaEl.getAttribute('data-instance-url'); + // @ts-expect-error mCaptcha.default({ siteKey: { instanceUrl: new URL(instanceURL), diff --git a/web_src/js/features/citation.ts b/web_src/js/features/citation.ts index c9b07efe77811..8fc6beabfb2d8 100644 --- a/web_src/js/features/citation.ts +++ b/web_src/js/features/citation.ts @@ -3,7 +3,7 @@ import {fomanticQuery} from '../modules/fomantic/base.ts'; const {pageData} = window.config; -async function initInputCitationValue(citationCopyApa, citationCopyBibtex) { +async function initInputCitationValue(citationCopyApa: HTMLButtonElement, citationCopyBibtex: HTMLButtonElement) { const [{Cite, plugins}] = await Promise.all([ import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'), import(/* webpackChunkName: "citation-js-formats" */'@citation-js/plugin-software-formats'), @@ -27,9 +27,9 @@ export async function initCitationFileCopyContent() { if (!pageData.citationFileContent) return; - const citationCopyApa = document.querySelector('#citation-copy-apa'); - const citationCopyBibtex = document.querySelector('#citation-copy-bibtex'); - const inputContent = document.querySelector('#citation-copy-content'); + const citationCopyApa = document.querySelector('#citation-copy-apa'); + const citationCopyBibtex = document.querySelector('#citation-copy-bibtex'); + const inputContent = document.querySelector('#citation-copy-content'); if ((!citationCopyApa && !citationCopyBibtex) || !inputContent) return; @@ -41,7 +41,7 @@ export async function initCitationFileCopyContent() { citationCopyApa.classList.toggle('primary', !isBibtex); }; - document.querySelector('#cite-repo-button')?.addEventListener('click', async (e) => { + document.querySelector('#cite-repo-button')?.addEventListener('click', async (e: MouseEvent & {target: HTMLAnchorElement}) => { const dropdownBtn = e.target.closest('.ui.dropdown.button'); dropdownBtn.classList.add('is-loading'); diff --git a/web_src/js/features/clipboard.ts b/web_src/js/features/clipboard.ts index 8de150d0f9821..8f40f34f7410f 100644 --- a/web_src/js/features/clipboard.ts +++ b/web_src/js/features/clipboard.ts @@ -9,7 +9,7 @@ const {copy_success, copy_error} = window.config.i18n; // - data-clipboard-target: Holds a selector for a or