From 09a88fb17ea252384d29f7dcb0828962ca5a9c3e Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 10 Feb 2026 06:09:56 +0100 Subject: [PATCH] Misc typescript tweaks (#36523) Some minor refactors, disable one obsolete lint rule, fix another. The tribute type issue is not fully fixed and I'm pretty sure it must be an error in their types. --- eslint.config.ts | 4 ++-- web_src/js/features/tribute.ts | 8 ++++++-- web_src/js/globals.d.ts | 8 +------- web_src/js/render/ansi.ts | 2 +- web_src/js/types.ts | 8 ++++++++ web_src/js/utils/glob.test.ts | 1 - 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 8d5b435397..5815702c89 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -342,7 +342,7 @@ export default defineConfig([ 'import-x/first': [2], 'import-x/group-exports': [0], 'import-x/max-dependencies': [0], - 'import-x/named': [2], + 'import-x/named': [0], 'import-x/namespace': [0], 'import-x/newline-after-import': [0], 'import-x/no-absolute-path': [0], @@ -987,7 +987,7 @@ export default defineConfig([ 'vitest/require-to-throw-message': [0], 'vitest/require-top-level-describe': [0], 'vitest/valid-describe-callback': [2], - 'vitest/valid-expect': [2], + 'vitest/valid-expect': [2, {maxArgs: 2}], 'vitest/valid-title': [2], }, }, diff --git a/web_src/js/features/tribute.ts b/web_src/js/features/tribute.ts index 0239204f9e..8434a9b2ac 100644 --- a/web_src/js/features/tribute.ts +++ b/web_src/js/features/tribute.ts @@ -1,6 +1,7 @@ import {emojiKeys, emojiHTML, emojiString} from './emoji.ts'; import {html, htmlRaw} from '../utils/html.ts'; import type {TributeCollection} from 'tributejs'; +import type {MentionValue} from '../types.ts'; export async function attachTribute(element: HTMLElement) { const {default: Tribute} = await import(/* webpackChunkName: "tribute" */'tributejs'); @@ -28,7 +29,7 @@ export async function attachTribute(element: HTMLElement) { }, }; - const mentionCollection: TributeCollection> = { + const mentionCollection: TributeCollection = { values: window.config.mentionValues, requireLeadingSpace: true, menuItemTemplate: (item) => { @@ -44,7 +45,10 @@ export async function attachTribute(element: HTMLElement) { }; const tribute = new Tribute({ - collection: [emojiCollection as TributeCollection, mentionCollection], + collection: [ + emojiCollection as TributeCollection, + mentionCollection as TributeCollection, + ], noMatchTemplate: () => '', }); tribute.attach(element); diff --git a/web_src/js/globals.d.ts b/web_src/js/globals.d.ts index ee90bc3c9c..8de6581dbc 100644 --- a/web_src/js/globals.d.ts +++ b/web_src/js/globals.d.ts @@ -29,13 +29,7 @@ interface Window { pageData: Record, notificationSettings: Record, enableTimeTracking: boolean, - mentionValues: Array<{ - key: string, - value: string, - name: string, - fullname: string, - avatar: string, - }>, + mentionValues: Array, mermaidMaxSourceCharacters: number, i18n: Record, }, diff --git a/web_src/js/render/ansi.ts b/web_src/js/render/ansi.ts index 685e916c9a..f5429ef6ad 100644 --- a/web_src/js/render/ansi.ts +++ b/web_src/js/render/ansi.ts @@ -31,7 +31,7 @@ export function renderAnsi(line: string): string { // handle "\rReading...1%\rReading...5%\rReading...100%", // convert it into a multiple-line string: "Reading...1%\nReading...5%\nReading...100%" - const lines = []; + const lines: Array = []; for (const part of line.split('\r')) { if (part === '') continue; const partHtml = ansi_up.ansi_to_html(part); diff --git a/web_src/js/types.ts b/web_src/js/types.ts index 56527729a1..815dfd2f82 100644 --- a/web_src/js/types.ts +++ b/web_src/js/types.ts @@ -2,6 +2,14 @@ export type IntervalId = ReturnType; export type Intent = 'error' | 'warning' | 'info'; +export type MentionValue = { + key: string, + value: string, + name: string, + fullname: string, + avatar: string, +}; + export type RequestData = string | FormData | URLSearchParams | Record; export type RequestOpts = { diff --git a/web_src/js/utils/glob.test.ts b/web_src/js/utils/glob.test.ts index 0c5d9783c0..fbf83a6cfe 100644 --- a/web_src/js/utils/glob.test.ts +++ b/web_src/js/utils/glob.test.ts @@ -117,7 +117,6 @@ test('GlobCompiler', async () => { for (const c of golangCases) { const compiled = globCompile(c.pattern, c.separators); const msg = `pattern: ${c.pattern}, input: ${c.input}, separators: ${c.separators || '(none)'}, compiled: ${compiled.regexpPattern}`; - // eslint-disable-next-line vitest/valid-expect -- Unlike Jest, Vitest supports a message as the second argument expect(compiled.regexp.test(c.input), msg).toBe(c.matched); }