From b6afddd1818e71acba04f040dd7aef172f3089c9 Mon Sep 17 00:00:00 2001 From: wackbyte Date: Sun, 12 Jan 2025 09:05:05 +0000 Subject: [PATCH] Reduce use of type casting (#3723) --- ts/editable/mathjax.ts | 2 +- ts/editor/NoteEditor.svelte | 8 +++++--- ts/editor/rich-text-input/RichTextStyles.svelte | 8 ++++---- ts/html-filter/styling.ts | 2 +- ts/lib/components/WithFloating.svelte | 2 +- ts/lib/components/WithOverlay.svelte | 2 +- ts/lib/components/WithState.svelte | 2 +- ts/lib/domlib/location/document.ts | 2 +- ts/lib/tag-editor/TagEditor.svelte | 4 ++-- ts/reviewer/images.ts | 4 ++-- ts/reviewer/lib.test.ts | 2 +- ts/reviewer/preload.ts | 2 +- ts/routes/card-info/ForgettingCurve.svelte | 2 +- ts/routes/change-notetype/lib.ts | 6 +++--- ts/routes/deck-options/AdvancedOptions.svelte | 2 +- ts/routes/deck-options/AudioOptions.svelte | 2 +- ts/routes/deck-options/AutoAdvance.svelte | 2 +- ts/routes/deck-options/BuryOptions.svelte | 2 +- ts/routes/deck-options/DailyLimits.svelte | 2 +- ts/routes/deck-options/DisplayOrder.svelte | 2 +- ts/routes/deck-options/FsrsOptions.svelte | 4 ++-- ts/routes/deck-options/FsrsOptionsOuter.svelte | 2 +- ts/routes/deck-options/LapseOptions.svelte | 2 +- ts/routes/deck-options/NewOptions.svelte | 2 +- ts/routes/deck-options/TimerOptions.svelte | 2 +- ts/routes/graphs/AddedGraph.svelte | 2 +- ts/routes/graphs/ButtonsGraph.svelte | 2 +- ts/routes/graphs/CalendarGraph.svelte | 6 +++--- ts/routes/graphs/CardCounts.svelte | 6 +++--- ts/routes/graphs/DifficultyGraph.svelte | 2 +- ts/routes/graphs/EaseGraph.svelte | 2 +- ts/routes/graphs/FutureDue.svelte | 6 +++--- ts/routes/graphs/HistogramGraph.svelte | 2 +- ts/routes/graphs/HourGraph.svelte | 2 +- ts/routes/graphs/IntervalsGraph.svelte | 2 +- ts/routes/graphs/RangeBox.svelte | 4 ++-- ts/routes/graphs/RetrievabilityGraph.svelte | 2 +- ts/routes/graphs/ReviewsGraph.svelte | 4 ++-- ts/routes/graphs/StabilityGraph.svelte | 2 +- ts/routes/graphs/Tooltip.svelte | 2 +- ts/routes/graphs/WithGraphData.svelte | 2 +- ts/routes/graphs/buttons.ts | 6 +++--- ts/routes/graphs/calendar.ts | 4 ++-- ts/routes/graphs/card-counts.ts | 5 ++--- ts/routes/graphs/histogram-graph.ts | 2 +- ts/routes/graphs/index.ts | 2 +- ts/routes/graphs/reviews.ts | 2 +- ts/routes/image-occlusion/review.ts | 12 ++++++------ ts/routes/image-occlusion/shapes/to-cloze.ts | 4 ++-- ts/routes/image-occlusion/tools/tool-zoom.ts | 2 +- .../import-anki-package/ImportAnkiPackagePage.svelte | 2 +- ts/routes/import-csv/FileOptions.svelte | 2 +- ts/routes/import-csv/ImportOptions.svelte | 2 +- ts/routes/import-page/[...path]/+page.svelte | 4 ++-- 54 files changed, 85 insertions(+), 84 deletions(-) diff --git a/ts/editable/mathjax.ts b/ts/editable/mathjax.ts index 94ea32118..e185d7935 100644 --- a/ts/editable/mathjax.ts +++ b/ts/editable/mathjax.ts @@ -18,7 +18,7 @@ function getCSS(nightMode: boolean, fontSize: number): string { } function getStyle(css: string): HTMLStyleElement { - const style = document.createElement("style") as HTMLStyleElement; + const style = document.createElement("style"); style.appendChild(document.createTextNode(css)); return style; } diff --git a/ts/editor/NoteEditor.svelte b/ts/editor/NoteEditor.svelte index efe2ec28a..77c394f56 100644 --- a/ts/editor/NoteEditor.svelte +++ b/ts/editor/NoteEditor.svelte @@ -386,9 +386,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html * Enable/Disable add-on buttons that do not have the `perm` class */ function setAddonButtonsDisabled(disabled: boolean): void { - document.querySelectorAll("button.linkb:not(.perm)").forEach((button) => { - (button as HTMLButtonElement).disabled = disabled; - }); + document + .querySelectorAll("button.linkb:not(.perm)") + .forEach((button) => { + button.disabled = disabled; + }); } import { ImageOcclusionFieldIndexes } from "@generated/anki/image_occlusion_pb"; diff --git a/ts/editor/rich-text-input/RichTextStyles.svelte b/ts/editor/rich-text-input/RichTextStyles.svelte index eb8c0a3c7..b4f9cae0c 100644 --- a/ts/editor/rich-text-input/RichTextStyles.svelte +++ b/ts/editor/rich-text-input/RichTextStyles.svelte @@ -43,17 +43,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html $: setStyling("fontSize", fontSize + "px"); $: setStyling("direction", direction); - const styles = [ + const styles: StyleLinkType[] = [ { id: "rootStyle", - type: "link" as "link", + type: "link", href: "./_anki/css/editable.css", - } as StyleLinkType, + }, ]; function attachToShadow(element: Element) { const customStyles = mount(CustomStyles, { - target: element.shadowRoot as any, + target: element.shadowRoot!, props: { styles }, }); customStyles.addStyleTag("userBase").then((styleTag) => { diff --git a/ts/html-filter/styling.ts b/ts/html-filter/styling.ts index feb1adec6..ec8699eeb 100644 --- a/ts/html-filter/styling.ts +++ b/ts/html-filter/styling.ts @@ -16,7 +16,7 @@ function filterStyling( ): (element: HTMLElement) => void { return (element: HTMLElement): void => { // jsdom does not support @@iterator, so manually iterate - const toRemove = [] as string[]; + const toRemove: string[] = []; for (let i = 0; i < element.style.length; i++) { const key = element.style.item(i); const value = element.style.getPropertyValue(key); diff --git a/ts/lib/components/WithFloating.svelte b/ts/lib/components/WithFloating.svelte index b8e19ef35..3c0bc62e5 100644 --- a/ts/lib/components/WithFloating.svelte +++ b/ts/lib/components/WithFloating.svelte @@ -35,7 +35,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export { placement as preferredPlacement }; /* Used by Popover to set animation direction depending on placement */ - const placementPromise = writable(undefined as Promise | undefined); + const placementPromise = writable | undefined>(); setContext(floatingKey, placementPromise); export let offset = 5; diff --git a/ts/lib/components/WithOverlay.svelte b/ts/lib/components/WithOverlay.svelte index 01aac265f..e00f802ab 100644 --- a/ts/lib/components/WithOverlay.svelte +++ b/ts/lib/components/WithOverlay.svelte @@ -27,7 +27,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { overlayKey } from "./context-keys"; /* Used by Popover to set animation direction depending on placement */ - const placementPromise = writable(undefined as Promise | undefined); + const placementPromise = writable | undefined>(); setContext(overlayKey, placementPromise); export let padding = 0; diff --git a/ts/lib/components/WithState.svelte b/ts/lib/components/WithState.svelte index 701a8cc28..abffd0857 100644 --- a/ts/lib/components/WithState.svelte +++ b/ts/lib/components/WithState.svelte @@ -17,7 +17,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html callback: (key: KeyType) => Promise, ): void { stateStore.update((map: StateMap): StateMap => { - const newMap = new Map() as StateMap; + const newMap: StateMap = new Map(); for (const key of map.keys()) { newMap.set(key, callback(key)); diff --git a/ts/lib/domlib/location/document.ts b/ts/lib/domlib/location/document.ts index b72a242ee..06c0391d7 100644 --- a/ts/lib/domlib/location/document.ts +++ b/ts/lib/domlib/location/document.ts @@ -50,7 +50,7 @@ export function restoreSelection(base: Node, location: SelectionLocation): void base, selection, range, - location as SelectionLocationContent, + location, ); } } diff --git a/ts/lib/tag-editor/TagEditor.svelte b/ts/lib/tag-editor/TagEditor.svelte index 9659c4bdd..cbbbf3f57 100644 --- a/ts/lib/tag-editor/TagEditor.svelte +++ b/ts/lib/tag-editor/TagEditor.svelte @@ -375,10 +375,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html function deleteSelectedTags() { tagTypes - .map((tag, index) => [tag.selected, index]) + .map((tag, index): [boolean, number] => [tag.selected, index]) .filter(([selected]) => selected) .reverse() - .forEach(([, index]) => deleteTagAt(index as number)); + .forEach(([, index]) => deleteTagAt(index)); deselect(); saveTags(); } diff --git a/ts/reviewer/images.ts b/ts/reviewer/images.ts index 19c218409..05de24158 100644 --- a/ts/reviewer/images.ts +++ b/ts/reviewer/images.ts @@ -19,8 +19,8 @@ function imageLoaded(img: HTMLImageElement): Promise { } function extractImageSrcs(fragment: DocumentFragment): string[] { - const srcs = [...fragment.querySelectorAll("img[src]")].map( - (img) => (img as HTMLImageElement).src, + const srcs = [...fragment.querySelectorAll("img[src]")].map( + (img) => img.src, ); return srcs; } diff --git a/ts/reviewer/lib.test.ts b/ts/reviewer/lib.test.ts index ce1b2649b..d2fc81664 100644 --- a/ts/reviewer/lib.test.ts +++ b/ts/reviewer/lib.test.ts @@ -85,7 +85,7 @@ function exampleInput(): SchedulingStatesWithContext { test("can change oneof", () => { let states = exampleInput().states!; - const jsonStates = states.toJson({ "emitDefaultValues": true }) as any; + const jsonStates = states.toJson({ "emitDefaultValues": true }); // again should be a relearning state const inner = states.again?.kind?.value?.kind; assert(inner?.case === "relearning"); diff --git a/ts/reviewer/preload.ts b/ts/reviewer/preload.ts index 9adb097f5..8f63b639a 100644 --- a/ts/reviewer/preload.ts +++ b/ts/reviewer/preload.ts @@ -34,7 +34,7 @@ function createPreloadLink(href: string, as: string): HTMLLinkElement { } function extractExternalStyleSheets(fragment: DocumentFragment): CSSElement[] { - return ([...fragment.querySelectorAll("style, link")] as CSSElement[]) + return [...fragment.querySelectorAll("style, link")] .filter((css) => (css instanceof HTMLStyleElement && css.innerHTML.includes("@import")) || (css instanceof HTMLLinkElement && css.rel === "stylesheet") diff --git a/ts/routes/card-info/ForgettingCurve.svelte b/ts/routes/card-info/ForgettingCurve.svelte index 131473269..47322433a 100644 --- a/ts/routes/card-info/ForgettingCurve.svelte +++ b/ts/routes/card-info/ForgettingCurve.svelte @@ -21,7 +21,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let revlog: RevlogEntry[]; export let desiredRetention: number; - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; const bounds = defaultGraphBounds(); const title = tr.cardStatsFsrsForgettingCurveTitle(); diff --git a/ts/routes/change-notetype/lib.ts b/ts/routes/change-notetype/lib.ts index 6fa2a776a..029236099 100644 --- a/ts/routes/change-notetype/lib.ts +++ b/ts/routes/change-notetype/lib.ts @@ -93,12 +93,12 @@ export class ChangeNotetypeInfoWrapper { } input(): ChangeNotetypeRequest { - return this.info.input as ChangeNotetypeRequest; + return this.info.input!; } /** Pack changes back into input message for saving. */ intoInput(): ChangeNotetypeRequest { - const input = this.info.input as ChangeNotetypeRequest; + const input = this.info.input!; input.newFields = nullToNegativeOne(this.fields); if (this.templates) { input.newTemplates = nullToNegativeOne(this.templates); @@ -194,7 +194,7 @@ export class ChangeNotetypeState { idx, name: entry.name, current: entry.id === currentId, - } as NotetypeListEntry), + } satisfies NotetypeListEntry), ); } } diff --git a/ts/routes/deck-options/AdvancedOptions.svelte b/ts/routes/deck-options/AdvancedOptions.svelte index 2bc95668c..5662c48a0 100644 --- a/ts/routes/deck-options/AdvancedOptions.svelte +++ b/ts/routes/deck-options/AdvancedOptions.svelte @@ -81,7 +81,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html url: "https://faqs.ankiweb.net/the-2021-scheduler.html#add-ons-and-custom-scheduling", }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/AudioOptions.svelte b/ts/routes/deck-options/AudioOptions.svelte index 0e0195587..9a0b158e4 100644 --- a/ts/routes/deck-options/AudioOptions.svelte +++ b/ts/routes/deck-options/AudioOptions.svelte @@ -34,7 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html help: tr.deckConfigAlwaysIncludeQuestionAudioTooltip(), }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/AutoAdvance.svelte b/ts/routes/deck-options/AutoAdvance.svelte index f17f0e5d9..13f310fab 100644 --- a/ts/routes/deck-options/AutoAdvance.svelte +++ b/ts/routes/deck-options/AutoAdvance.svelte @@ -49,7 +49,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html help: tr.deckConfigAnswerActionTooltip2(), }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/BuryOptions.svelte b/ts/routes/deck-options/BuryOptions.svelte index 88a075f97..e034ba0ca 100644 --- a/ts/routes/deck-options/BuryOptions.svelte +++ b/ts/routes/deck-options/BuryOptions.svelte @@ -40,7 +40,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html help: tr.deckConfigBuryInterdayLearningTooltip() + priorityTooltip, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/DailyLimits.svelte b/ts/routes/deck-options/DailyLimits.svelte index d3e5ce74c..9b156ca00 100644 --- a/ts/routes/deck-options/DailyLimits.svelte +++ b/ts/routes/deck-options/DailyLimits.svelte @@ -143,7 +143,7 @@ url: HelpPage.DeckOptions.newCardsday, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/DisplayOrder.svelte b/ts/routes/deck-options/DisplayOrder.svelte index 5ea8d1d89..956400cc8 100644 --- a/ts/routes/deck-options/DisplayOrder.svelte +++ b/ts/routes/deck-options/DisplayOrder.svelte @@ -97,7 +97,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html help: tr.deckConfigReviewSortOrderTooltip() + currentDeck, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/FsrsOptions.svelte b/ts/routes/deck-options/FsrsOptions.svelte index ac79fa2f7..fb4c67487 100644 --- a/ts/routes/deck-options/FsrsOptions.svelte +++ b/ts/routes/deck-options/FsrsOptions.svelte @@ -300,10 +300,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html return tr.deckConfigPredictedOptimalRetention({ num: retention.toFixed(2) }); } - let tableData: TableDatum[] = [] as any; + let tableData: TableDatum[] = []; const bounds = defaultGraphBounds(); bounds.marginLeft += 8; - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; let simulationNumber = 0; let points: Point[] = []; diff --git a/ts/routes/deck-options/FsrsOptionsOuter.svelte b/ts/routes/deck-options/FsrsOptionsOuter.svelte index f21d7ff3c..89545b8c1 100644 --- a/ts/routes/deck-options/FsrsOptionsOuter.svelte +++ b/ts/routes/deck-options/FsrsOptionsOuter.svelte @@ -55,7 +55,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html sched: HelpItemScheduler.FSRS, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/LapseOptions.svelte b/ts/routes/deck-options/LapseOptions.svelte index 510999cb4..d1d089664 100644 --- a/ts/routes/deck-options/LapseOptions.svelte +++ b/ts/routes/deck-options/LapseOptions.svelte @@ -68,7 +68,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html url: HelpPage.Leeches.waiting, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/NewOptions.svelte b/ts/routes/deck-options/NewOptions.svelte index 74463b490..192be087c 100644 --- a/ts/routes/deck-options/NewOptions.svelte +++ b/ts/routes/deck-options/NewOptions.svelte @@ -80,7 +80,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html url: HelpPage.DeckOptions.insertionOrder, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/deck-options/TimerOptions.svelte b/ts/routes/deck-options/TimerOptions.svelte index 5617063a9..5f5e91736 100644 --- a/ts/routes/deck-options/TimerOptions.svelte +++ b/ts/routes/deck-options/TimerOptions.svelte @@ -45,7 +45,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html help: tr.deckConfigStopTimerOnAnswerTooltip(), }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/graphs/AddedGraph.svelte b/ts/routes/graphs/AddedGraph.svelte index b3ac60b82..28567bc7d 100644 --- a/ts/routes/graphs/AddedGraph.svelte +++ b/ts/routes/graphs/AddedGraph.svelte @@ -22,7 +22,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let sourceData: GraphsResponse | null = null; export let prefs: GraphPrefs; - let histogramData = null as HistogramData | null; + let histogramData: HistogramData | null = null; let tableData: TableDatum[] = []; let graphRange: GraphRange = GraphRange.Month; diff --git a/ts/routes/graphs/ButtonsGraph.svelte b/ts/routes/graphs/ButtonsGraph.svelte index 846e1e7e6..52c06867e 100644 --- a/ts/routes/graphs/ButtonsGraph.svelte +++ b/ts/routes/graphs/ButtonsGraph.svelte @@ -23,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const bounds = defaultGraphBounds(); - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; $: if (sourceData) { renderButtons(svg as SVGElement, bounds, sourceData, graphRange); diff --git a/ts/routes/graphs/CalendarGraph.svelte b/ts/routes/graphs/CalendarGraph.svelte index a8907ee00..fed64587a 100644 --- a/ts/routes/graphs/CalendarGraph.svelte +++ b/ts/routes/graphs/CalendarGraph.svelte @@ -30,13 +30,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html bounds.marginLeft = 20; bounds.marginRight = 20; - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; const maxYear = new Date().getFullYear(); let minYear = 0; let targetYear = maxYear; $: if (sourceData) { - graphData = gatherData(sourceData, $prefs.calendarFirstDayOfWeek as number); + graphData = gatherData(sourceData, $prefs.calendarFirstDayOfWeek); renderCalendar( svg as SVGElement, bounds, @@ -52,7 +52,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html $: { if (revlogRange < RevlogRange.Year) { minYear = maxYear; - } else if ((revlogRange as RevlogRange) === RevlogRange.Year) { + } else if (revlogRange === RevlogRange.Year) { minYear = maxYear - 1; } else { minYear = 2000; diff --git a/ts/routes/graphs/CardCounts.svelte b/ts/routes/graphs/CardCounts.svelte index 5aea6d52d..a561d4997 100644 --- a/ts/routes/graphs/CardCounts.svelte +++ b/ts/routes/graphs/CardCounts.svelte @@ -20,14 +20,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; const bounds = defaultGraphBounds(); bounds.width = 225; bounds.marginBottom = 0; - let graphData = null as unknown as GraphData; - let tableData = null as unknown as TableDatum[]; + let graphData: GraphData = null!; + let tableData: TableDatum[] = null!; $: { graphData = gatherData(sourceData, $prefs.cardCountsSeparateInactive); diff --git a/ts/routes/graphs/DifficultyGraph.svelte b/ts/routes/graphs/DifficultyGraph.svelte index a28466572..4eea03727 100644 --- a/ts/routes/graphs/DifficultyGraph.svelte +++ b/ts/routes/graphs/DifficultyGraph.svelte @@ -20,7 +20,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); - let histogramData = null as HistogramData | null; + let histogramData: HistogramData | null = null; let tableData: TableDatum[] = []; $: if (sourceData) { diff --git a/ts/routes/graphs/EaseGraph.svelte b/ts/routes/graphs/EaseGraph.svelte index 78bd24014..112604a6e 100644 --- a/ts/routes/graphs/EaseGraph.svelte +++ b/ts/routes/graphs/EaseGraph.svelte @@ -20,7 +20,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); - let histogramData = null as HistogramData | null; + let histogramData: HistogramData | null = null; let tableData: TableDatum[] = []; $: if (sourceData) { diff --git a/ts/routes/graphs/FutureDue.svelte b/ts/routes/graphs/FutureDue.svelte index ad33f9e67..3ed75a32e 100644 --- a/ts/routes/graphs/FutureDue.svelte +++ b/ts/routes/graphs/FutureDue.svelte @@ -24,9 +24,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); - let graphData = null as GraphData | null; - let histogramData = null as HistogramData | null; - let tableData: TableDatum[] = [] as any; + let graphData: GraphData | null = null; + let histogramData: HistogramData | null = null; + let tableData: TableDatum[] = []; let graphRange: GraphRange = GraphRange.Month; $: if (sourceData) { diff --git a/ts/routes/graphs/HistogramGraph.svelte b/ts/routes/graphs/HistogramGraph.svelte index 5d47ca46a..7afb78c1c 100644 --- a/ts/routes/graphs/HistogramGraph.svelte +++ b/ts/routes/graphs/HistogramGraph.svelte @@ -14,7 +14,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let data: HistogramData | null = null; const bounds = defaultGraphBounds(); - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; $: histogramGraph(svg as SVGElement, bounds, data); diff --git a/ts/routes/graphs/HourGraph.svelte b/ts/routes/graphs/HourGraph.svelte index 97206492a..c8c8c83ab 100644 --- a/ts/routes/graphs/HourGraph.svelte +++ b/ts/routes/graphs/HourGraph.svelte @@ -23,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const bounds = defaultGraphBounds(); - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; $: if (sourceData) { renderHours(svg as SVGElement, bounds, sourceData, graphRange); diff --git a/ts/routes/graphs/IntervalsGraph.svelte b/ts/routes/graphs/IntervalsGraph.svelte index dd0a50e9b..7e752f1b8 100644 --- a/ts/routes/graphs/IntervalsGraph.svelte +++ b/ts/routes/graphs/IntervalsGraph.svelte @@ -28,7 +28,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); let intervalData: IntervalGraphData | null = null; - let histogramData = null as HistogramData | null; + let histogramData: HistogramData | null = null; let tableData: TableDatum[] = []; let range = IntervalRange.Percentile95; diff --git a/ts/routes/graphs/RangeBox.svelte b/ts/routes/graphs/RangeBox.svelte index d1388d639..25695788e 100644 --- a/ts/routes/graphs/RangeBox.svelte +++ b/ts/routes/graphs/RangeBox.svelte @@ -34,7 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let displayedSearch = $search; $: { - switch (searchRange as SearchRange) { + switch (searchRange) { case SearchRange.Deck: $search = displayedSearch = "deck:current"; break; @@ -45,7 +45,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } $: { - switch (revlogRange as RevlogRange) { + switch (revlogRange) { case RevlogRange.Year: $days = 365; break; diff --git a/ts/routes/graphs/RetrievabilityGraph.svelte b/ts/routes/graphs/RetrievabilityGraph.svelte index 64876465e..348c5239a 100644 --- a/ts/routes/graphs/RetrievabilityGraph.svelte +++ b/ts/routes/graphs/RetrievabilityGraph.svelte @@ -20,7 +20,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); - let histogramData = null as HistogramData | null; + let histogramData: HistogramData | null = null; let tableData: TableDatum[] = []; $: if (sourceData) { diff --git a/ts/routes/graphs/ReviewsGraph.svelte b/ts/routes/graphs/ReviewsGraph.svelte index ab2f4de3c..530995ba9 100644 --- a/ts/routes/graphs/ReviewsGraph.svelte +++ b/ts/routes/graphs/ReviewsGraph.svelte @@ -25,7 +25,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let graphData: GraphData | null = null; const bounds = defaultGraphBounds(); - let svg = null as HTMLElement | SVGElement | null; + let svg: HTMLElement | SVGElement | null = null; let graphRange: GraphRange = GraphRange.Month; let showTime = false; @@ -33,7 +33,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html graphData = gatherData(sourceData); } - let tableData: TableDatum[] = [] as any; + let tableData: TableDatum[] = []; $: if (graphData) { tableData = renderReviews( svg as SVGElement, diff --git a/ts/routes/graphs/StabilityGraph.svelte b/ts/routes/graphs/StabilityGraph.svelte index 4e0a69f5c..73aa3e8f9 100644 --- a/ts/routes/graphs/StabilityGraph.svelte +++ b/ts/routes/graphs/StabilityGraph.svelte @@ -28,7 +28,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); let intervalData: IntervalGraphData | null = null; - let histogramData = null as HistogramData | null; + let histogramData: HistogramData | null = null; let tableData: TableDatum[] = []; let range = IntervalRange.Percentile95; diff --git a/ts/routes/graphs/Tooltip.svelte b/ts/routes/graphs/Tooltip.svelte index 2ae6e07d7..aeb9a67e9 100644 --- a/ts/routes/graphs/Tooltip.svelte +++ b/ts/routes/graphs/Tooltip.svelte @@ -10,7 +10,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let y: number = 0; export let show = true; - let container = null as unknown as HTMLDivElement; + let container: HTMLDivElement | null = null; let adjustedX: number, adjustedY: number; diff --git a/ts/routes/graphs/WithGraphData.svelte b/ts/routes/graphs/WithGraphData.svelte index ce8a9bd9e..5a9d3e996 100644 --- a/ts/routes/graphs/WithGraphData.svelte +++ b/ts/routes/graphs/WithGraphData.svelte @@ -23,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html setGraphPreferences, ); - let sourceData = null as null | GraphsResponse; + let sourceData: GraphsResponse | null = null; let loading = true; $: updateSourceData($search, $days); diff --git a/ts/routes/graphs/buttons.ts b/ts/routes/graphs/buttons.ts index 85755085a..2805f89c6 100644 --- a/ts/routes/graphs/buttons.ts +++ b/ts/routes/graphs/buttons.ts @@ -75,21 +75,21 @@ export function renderButtons( buttonNum: idx + 1, group: "learning", count, - } as Datum; + } satisfies Datum; }), ...sourceData.young.map((count: number, idx: number) => { return { buttonNum: idx + 1, group: "young", count, - } as Datum; + } satisfies Datum; }), ...sourceData.mature.map((count: number, idx: number) => { return { buttonNum: idx + 1, group: "mature", count, - } as Datum; + } satisfies Datum; }), ]; diff --git a/ts/routes/graphs/calendar.ts b/ts/routes/graphs/calendar.ts index a121eba2c..863923095 100644 --- a/ts/routes/graphs/calendar.ts +++ b/ts/routes/graphs/calendar.ts @@ -98,7 +98,7 @@ export function renderCalendar( const weekNumber = sourceData.timeFunction.count(timeYear(date), date); const weekDay = timeDay.count(sourceData.timeFunction(date), date); const yearDay = timeDay.count(timeYear(date), date); - dayMap.set(yearDay, { day, count, weekNumber, weekDay, date } as DayDatum); + dayMap.set(yearDay, { day, count, weekNumber, weekDay, date }); } if (!maxCount) { @@ -132,7 +132,7 @@ export function renderCalendar( weekNumber, weekDay, date, - } as DayDatum); + }); } } const data = Array.from(dayMap.values()); diff --git a/ts/routes/graphs/card-counts.ts b/ts/routes/graphs/card-counts.ts index d6fb9208c..e31c0a5b9 100644 --- a/ts/routes/graphs/card-counts.ts +++ b/ts/routes/graphs/card-counts.ts @@ -130,9 +130,8 @@ export function renderCards( count: count[1], show: count[2], query: count[3], - idx, total: n, - } as SummedDatum; + } satisfies SummedDatum; }); // ensuring a non-zero range makes the percentages not break // in an empty collection @@ -181,7 +180,7 @@ export function renderCards( percent: `${percent}%`, colour: barColours[idx], query: d.query, - } as TableDatum) + } satisfies TableDatum) : []; }); diff --git a/ts/routes/graphs/histogram-graph.ts b/ts/routes/graphs/histogram-graph.ts index da650c6ca..a101c985a 100644 --- a/ts/routes/graphs/histogram-graph.ts +++ b/ts/routes/graphs/histogram-graph.ts @@ -46,7 +46,7 @@ export function histogramGraph( setDataAvailable(svg, true); } - const binValue = data.binValue ?? ((bin: any): number => bin.length as number); + const binValue = data.binValue ?? ((bin: Bin) => bin.length); const x = data.scale.range([bounds.marginLeft, bounds.width - bounds.marginRight]); svg.select(".x-ticks") diff --git a/ts/routes/graphs/index.ts b/ts/routes/graphs/index.ts index d916ff782..6909bdb8b 100644 --- a/ts/routes/graphs/index.ts +++ b/ts/routes/graphs/index.ts @@ -20,7 +20,7 @@ export async function setupGraphs( { search = "deck:current", days = 365, - controller = null as typeof SvelteComponent | null, + controller = null satisfies typeof SvelteComponent | null, } = {}, ): Promise { checkNightMode(); diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index 8304371ff..7c18a9740 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -291,7 +291,7 @@ export function renderReviews( .attr("direction", "ltr"); svg.select("path.cumulative-overlay") - .datum(areaData as any) + .datum(areaData) .attr( "d", area() diff --git a/ts/routes/image-occlusion/review.ts b/ts/routes/image-occlusion/review.ts index 9a479fed5..84fb3babc 100644 --- a/ts/routes/image-occlusion/review.ts +++ b/ts/routes/image-occlusion/review.ts @@ -53,9 +53,9 @@ async function setupImageOcclusion(setupOptions?: SetupImageOcclusionOptions): P /** We must make sure the image has loaded before we can access its dimensions. * This can happen if not preloading, or if preloading takes too long. */ async function waitForImage(): Promise { - const image = document.querySelector( + const image = document.querySelector( "#image-occlusion-container img", - ) as HTMLImageElement | null; + ); if (!image) { // error will be handled later return; @@ -116,9 +116,9 @@ function calculateContainerSize( let oneTimeSetupDone = false; async function setupImageOcclusionInner(setupOptions?: SetupImageOcclusionOptions): Promise { - const canvas = document.querySelector( + const canvas = document.querySelector( "#image-occlusion-canvas", - ) as HTMLCanvasElement | null; + ); if (canvas == null) { return; } @@ -126,9 +126,9 @@ async function setupImageOcclusionInner(setupOptions?: SetupImageOcclusionOption const container = document.getElementById( "image-occlusion-container", ) as HTMLDivElement; - const image = document.querySelector( + const image = document.querySelector( "#image-occlusion-container img", - ) as HTMLImageElement; + ); if (image == null) { await setupI18n({ modules: [ diff --git a/ts/routes/image-occlusion/shapes/to-cloze.ts b/ts/routes/image-occlusion/shapes/to-cloze.ts index ca27c6fa5..102e9bbd4 100644 --- a/ts/routes/image-occlusion/shapes/to-cloze.ts +++ b/ts/routes/image-occlusion/shapes/to-cloze.ts @@ -60,7 +60,7 @@ export function exportShapesToClozeDeletions(occludeInactive: boolean): { if (shapeOrShapes instanceof Text) { ordinal = 0; } else if (missingOrdinals.length > 0) { - ordinal = missingOrdinals.shift() as number; + ordinal = missingOrdinals.shift()!; } else { ordinal = nextOrdinal; nextOrdinal++; @@ -96,7 +96,7 @@ export function baseShapesFromFabric(): ShapeOrShapes[] { && (activeObject.size() > 1) ? activeObject : null; - const objects = canvas.getObjects() as fabric.Object[]; + const objects = canvas.getObjects(); const boundingBox = getBoundingBoxSize(); // filter transparent rectangles return objects diff --git a/ts/routes/image-occlusion/tools/tool-zoom.ts b/ts/routes/image-occlusion/tools/tool-zoom.ts index 3d2ef0d6a..a2af9dd79 100644 --- a/ts/routes/image-occlusion/tools/tool-zoom.ts +++ b/ts/routes/image-occlusion/tools/tool-zoom.ts @@ -66,7 +66,7 @@ const zoomResetInner = (canvas: fabric.Canvas): void => { }; export const enablePinchZoom = (canvas: fabric.Canvas) => { - const hammer = new Hammer(upperCanvasElement(canvas)) as any; + const hammer = new Hammer(upperCanvasElement(canvas)); hammer.get("pinch").set({ enable: true }); hammer.on("pinchin pinchout", ev => { currentScale = Math.min(Math.max(minScale, ev.scale * zoomScale), maxScale); diff --git a/ts/routes/import-anki-package/ImportAnkiPackagePage.svelte b/ts/routes/import-anki-package/ImportAnkiPackagePage.svelte index 80a872fc7..cc75fda3e 100644 --- a/ts/routes/import-anki-package/ImportAnkiPackagePage.svelte +++ b/ts/routes/import-anki-package/ImportAnkiPackagePage.svelte @@ -51,7 +51,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html url: HelpPage.PackageImporting.updating, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/import-csv/FileOptions.svelte b/ts/routes/import-csv/FileOptions.svelte index 8872a6b38..182083865 100644 --- a/ts/routes/import-csv/FileOptions.svelte +++ b/ts/routes/import-csv/FileOptions.svelte @@ -35,7 +35,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html url: HelpPage.TextImporting.html, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/import-csv/ImportOptions.svelte b/ts/routes/import-csv/ImportOptions.svelte index e864448fb..2acde50eb 100644 --- a/ts/routes/import-csv/ImportOptions.svelte +++ b/ts/routes/import-csv/ImportOptions.svelte @@ -56,7 +56,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html url: HelpPage.TextImporting.root, }, }; - const helpSections = Object.values(settings) as HelpItem[]; + const helpSections: HelpItem[] = Object.values(settings); let modal: Modal; let carousel: Carousel; diff --git a/ts/routes/import-page/[...path]/+page.svelte b/ts/routes/import-page/[...path]/+page.svelte index 3373232f5..326738189 100644 --- a/ts/routes/import-page/[...path]/+page.svelte +++ b/ts/routes/import-page/[...path]/+page.svelte @@ -10,9 +10,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let data: PageData; - const importer = { + const importer: Importer = { doImport: () => importJsonFile({ val: data.path }, {}), - } as Importer; + };