#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Fix `any` types in frontend code (#7817)
James Brunton7b413ce92ba5
diff --git a/frontend/editor/src/core/components/shared/FilePickerModal.stories.tsx b/frontend/editor/src/core/components/shared/FilePickerModal.stories.tsxindex 51eac29632..5ac1aad9c6 100644--- a/frontend/editor/src/core/components/shared/FilePickerModal.stories.tsx+++ b/frontend/editor/src/core/components/shared/FilePickerModal.stories.tsx@@ -1,15 +1,23 @@import type { Meta, StoryObj } from "@storybook/react-vite";import FilePickerModal from "@app/components/shared/FilePickerModal";+import type { FileId } from "@app/types/file";const mockStoredFiles = [- { id: "file-1", name: "invoice.pdf", size: 245_000, thumbnail: null },{- id: "file-2",+ id: "file-1" as FileId,+ name: "invoice.pdf",+ size: 245_000,+ },+ {+ id: "file-2" as FileId,name: "contract-draft.pdf",size: 1_240_000,- thumbnail: null,},- { id: "file-3", name: "scanned-form.pdf", size: 3_400_000, thumbnail: null },+ {+ id: "file-3" as FileId,+ name: "scanned-form.pdf",+ size: 3_400_000,+ },];const meta = {diff --git a/frontend/editor/src/core/components/shared/FilePickerModal.tsx b/frontend/editor/src/core/components/shared/FilePickerModal.tsxindex d9fc6e9502..0372ea7bd6 100644--- a/frontend/editor/src/core/components/shared/FilePickerModal.tsx+++ b/frontend/editor/src/core/components/shared/FilePickerModal.tsx@@ -14,12 +14,20 @@ import { Button } from "@app/ui/Button";import { useTranslation } from "react-i18next";import DocumentThumbnail from "@app/components/shared/filePreview/DocumentThumbnail";import { FileId } from "@app/types/file";+import type { StoredStirlingFileRecord } from "@app/services/fileStorage";import { useFileActionTerminology } from "@app/hooks/useFileActionTerminology";+type StoredFileItem = Partial<StoredStirlingFileRecord> & {+ id: FileId;+ file?: File;+ arrayBuffer?: () => Promise<ArrayBuffer>;+ processedFile?: { isEncrypted?: boolean };+};+interface FilePickerModalProps {opened: boolean;onClose: () => void;- storedFiles: any[]; // Files from storage (various formats supported)+ storedFiles: StoredFileItem[];onSelectFiles: (selectedFiles: File[]) => void;}@@ -84,7 +92,7 @@ const FilePickerModal = ({const blob = new Blob([arrayBuffer], {type: fileItem.type || "application/pdf",});- return new File([blob], fileItem.name, {+ return new File([blob], fileItem.name ?? "", {type: fileItem.type || "application/pdf",lastModified: fileItem.lastModified || Date.now(),});@@ -95,7 +103,7 @@ const FilePickerModal = ({const blob = new Blob([fileItem.data], {type: fileItem.type || "application/pdf",});- return new File([blob], fileItem.name, {+ return new File([blob], fileItem.name ?? "", {type: fileItem.type || "application/pdf",lastModified: fileItem.lastModified || Date.now(),});@@ -211,7 +219,7 @@ const FilePickerModal = ({}}><DocumentThumbnail- file={file}+ file={file.file ?? null}thumbnail={file.processedFile?.isEncrypted? undefineddiff --git a/frontend/editor/src/core/components/tools/addStamp/StampPositionFormattingSettings.tsx b/frontend/editor/src/core/components/tools/addStamp/StampPositionFormattingSettings.tsxindex 76f8be4109..1d185f16e7 100644--- a/frontend/editor/src/core/components/tools/addStamp/StampPositionFormattingSettings.tsx+++ b/frontend/editor/src/core/components/tools/addStamp/StampPositionFormattingSettings.tsx@@ -60,8 +60,8 @@ const StampPositionFormattingSettings = ({onClick={() => {onParameterChange("position", idx);// Ensure we're using grid positioning, not custom overrides- onParameterChange("overrideX", -1 as any);- onParameterChange("overrideY", -1 as any);+ onParameterChange("overrideX", -1);+ onParameterChange("overrideY", -1);}}disabled={disabled}style={{@@ -257,7 +257,10 @@ const StampPositionFormattingSettings = ({label={t("AddStampRequest.margin", "Margin")}value={parameters.customMargin}onChange={(v) =>- onParameterChange("customMargin", (v as any) || "medium")+ onParameterChange(+ "customMargin",+ (v as AddStampParameters["customMargin"]) || "medium",+ )}data={[{ value: "small", label: t("margin.small", "Small") },diff --git a/frontend/editor/src/core/components/tools/addStamp/StampPreview.tsx b/frontend/editor/src/core/components/tools/addStamp/StampPreview.tsxindex 1c04414ae4..93d3a1e874 100644--- a/frontend/editor/src/core/components/tools/addStamp/StampPreview.tsx+++ b/frontend/editor/src/core/components/tools/addStamp/StampPreview.tsx@@ -172,11 +172,12 @@ export default function StampPreview({bottomPx: number;} | null>(null);useEffect(() => {- const itemStyle = style.item as any;+ const itemStyle = style.item;if (!itemStyle || containerSize.width <= 0 || containerSize.height <= 0)return;- const parse = (v: any) => parseFloat(String(v).replace("px", "")) || 0;+ const parse = (v: string | number | undefined) =>+ parseFloat(String(v).replace("px", "")) || 0;const leftPx = parse(itemStyle.left);const bottomPx = parse(itemStyle.bottom);const widthPx = parse(itemStyle.width);@@ -208,8 +209,8 @@ export default function StampPreview({const newLeftPts = Math.max(0, Math.min(maxLeftPx, newLeftPx)) / scaleX;const newBottomPts =Math.max(0, Math.min(maxBottomPx, newBottomPx)) / scaleY;- onParameterChange("overrideX", newLeftPts as any);- onParameterChange("overrideY", newBottomPts as any);+ onParameterChange("overrideX", newLeftPts);+ onParameterChange("overrideY", newBottomPts);}prevDimsRef.current = {@@ -249,7 +250,7 @@ export default function StampPreview({if (pageWidth <= 0 || pageHeight <= 0) return;// Recompute current x,y from style (so that we start from visual position)- const itemStyle = style.item as any;+ const itemStyle = style.item;const leftPx = parseFloat(String(itemStyle.left).replace("px", "")) || 0;const bottomPx =parseFloat(String(itemStyle.bottom).replace("px", "")) || 0;@@ -265,11 +266,11 @@ export default function StampPreview({const maxBottomPx = Math.max(0, pageHeight - heightPx);onParameterChange("overrideX",- (Math.max(0, Math.min(maxLeftPx, leftPx)) / scaleX) as any,+ Math.max(0, Math.min(maxLeftPx, leftPx)) / scaleX,);onParameterChange("overrideY",- (Math.max(0, Math.min(maxBottomPx, bottomPx)) / scaleY) as any,+ Math.max(0, Math.min(maxBottomPx, bottomPx)) / scaleY,);}};@@ -281,7 +282,7 @@ export default function StampPreview({e.preventDefault();ensureOverrides();- const item = style.item as any;+ const item = style.item;const left = parseFloat(String(item.left).replace("px", "")) || 0;const bottom = parseFloat(String(item.bottom).replace("px", "")) || 0;const width =@@ -336,8 +337,8 @@ export default function StampPreview({const scaleY = containerSize.height / heightPts;const newLeftPts = newLeftPx / scaleX;const newBottomPts = newBottomPx / scaleY;- onParameterChange("overrideX", newLeftPts as any);- onParameterChange("overrideY", newBottomPts as any);+ onParameterChange("overrideX", newLeftPts);+ onParameterChange("overrideY", newBottomPts);}if (drag.type === "resize") {@@ -346,13 +347,13 @@ export default function StampPreview({const scaleY = containerSize.height / heightPts;const newHeightPx = Math.max(1, drag.initHeight + (y - drag.startY));const newHeightPts = newHeightPx / scaleY;- onParameterChange("fontSize", newHeightPts as any);+ onParameterChange("fontSize", newHeightPts);}if (drag.type === "rotate") {const angle =Math.atan2(y - drag.centerY, x - drag.centerX) * (180 / Math.PI);- onParameterChange("rotation", angle as any);+ onParameterChange("rotation", angle);}};@@ -441,9 +442,12 @@ export default function StampPreview({className={`${styles.gridTile} ${selected || hoverTile === idx ? styles.gridTileSelected : ""} ${hoverTile === idx ? styles.gridTileHovered : ""}`}onClick={() => {// Clear overrides to use grid positioning and set position- onParameterChange("overrideX", -1 as any);- onParameterChange("overrideY", -1 as any);- onParameterChange("position", idx as any);+ onParameterChange("overrideX", -1);+ onParameterChange("overrideY", -1);+ onParameterChange(+ "position",+ idx as AddStampParameters["position"],+ );}}onMouseEnter={() => setHoverTile(idx)}onMouseLeave={() => setHoverTile(null)}diff --git a/frontend/editor/src/core/components/tools/addStamp/StampPreviewUtils.ts b/frontend/editor/src/core/components/tools/addStamp/StampPreviewUtils.tsindex 8ac3c73551..70b66b5705 100644--- a/frontend/editor/src/core/components/tools/addStamp/StampPreviewUtils.ts+++ b/frontend/editor/src/core/components/tools/addStamp/StampPreviewUtils.ts@@ -1,3 +1,4 @@+import type { CSSProperties } from "react";import type { AddStampParameters } from "@app/components/tools/addStamp/useAddStampParameters";export type ContainerSize = { width: number; height: number };@@ -54,7 +55,10 @@ export const getFirstSelectedPage = (input: string): number => {return 1;};-export type StampPreviewStyle = { container: any; item: any };+export type StampPreviewStyle = {+ container: CSSProperties;+ item: CSSProperties;+};// Unified per-alphabet preview adjustmentsexport type Alphabet =@@ -117,10 +121,10 @@ export const ALPHABET_PREVIEW_TWEAKS: Record<Alphabet, AlphabetTweaks> = {},};export const getAlphabetPreviewScale = (alphabet: string): number =>- (ALPHABET_PREVIEW_TWEAKS as any)[alphabet]?.scale ?? 1.0;+ ALPHABET_PREVIEW_TWEAKS[alphabet as Alphabet]?.scale ?? 1.0;export const getDefaultFontSizeForAlphabet = (alphabet: string): number => {- return (ALPHABET_PREVIEW_TWEAKS as any)[alphabet]?.defaultFontSize ?? 80;+ return ALPHABET_PREVIEW_TWEAKS[alphabet as Alphabet]?.defaultFontSize ?? 80;};export function computeStampPreviewStyle(@@ -138,8 +142,7 @@ export function computeStampPreviewStyle(const heightPts = pageSize?.heightPts ?? 841.89; // A4 height at 72 DPIconst scaleX = pageWidthPx / widthPts;const scaleY = pageHeightPx / heightPts;- if (pageWidthPx <= 0 || pageHeightPx <= 0)- return { item: {}, container: {} } as any;+ if (pageWidthPx <= 0 || pageHeightPx <= 0) return { item: {}, container: {} };const marginPts =((widthPts + heightPts) / 2) *@@ -215,8 +218,7 @@ export function computeStampPreviewStyle(const heightForY =parameters.stampType === "text"? heightPtsContent *- ((ALPHABET_PREVIEW_TWEAKS as any)[parameters.alphabet]- ?.capHeightRatio ?? 0.7)+ (ALPHABET_PREVIEW_TWEAKS[parameters.alphabet]?.capHeightRatio ?? 0.7): heightPtsContent;switch (Math.floor((position - 1) / 3)) {case 0: // Top@@ -241,7 +243,7 @@ export function computeStampPreviewStyle(getComputedStyle(document.documentElement).fontSize || "16",) || 16;const rowIndex = Math.floor((position - 1) / 3); // 0 top, 1 middle, 2 bottom- const offsets = (ALPHABET_PREVIEW_TWEAKS as any)[parameters.alphabet]+ const offsets = ALPHABET_PREVIEW_TWEAKS[parameters.alphabet]?.rowOffsetRem ?? [0, 0, 0];const offsetRem = offsets[rowIndex] ?? 0;yPx += offsetRem * rootFontSizePx;@@ -297,8 +299,7 @@ export function computeStampPreviewStyle(display: "flex",flexDirection: "column",justifyContent: "flex-start",- lineHeight:- (ALPHABET_PREVIEW_TWEAKS as any)[parameters.alphabet]?.lineHeight ?? 1,+ lineHeight: ALPHABET_PREVIEW_TWEAKS[parameters.alphabet]?.lineHeight ?? 1,alignItems,cursor: showQuickGrid ? "default" : "move",pointerEvents: showQuickGrid ? "none" : "auto",diff --git a/frontend/editor/src/core/components/tools/addStamp/StampSetupSettings.tsx b/frontend/editor/src/core/components/tools/addStamp/StampSetupSettings.tsxindex 25e2bc2243..06df3aeaf8 100644--- a/frontend/editor/src/core/components/tools/addStamp/StampSetupSettings.tsx+++ b/frontend/editor/src/core/components/tools/addStamp/StampSetupSettings.tsx@@ -265,7 +265,10 @@ const StampSetupSettings = ({const template = STAMP_TEMPLATES.find((t) => t.id === value);if (template) {onParameterChange("stampText", template.text);- onParameterChange("position", template.position as any);+ onParameterChange(+ "position",+ template.position as AddStampParameters["position"],+ );}}}clearable@@ -640,7 +643,8 @@ const StampSetupSettings = ({label={t("AddStampRequest.alphabet", "Alphabet")}value={parameters.alphabet}onChange={(v) => {- const nextAlphabet = (v as any) || "roman";+ const nextAlphabet =+ (v as AddStampParameters["alphabet"]) || "roman";onParameterChange("alphabet", nextAlphabet);const nextDefault = getDefaultFontSizeForAlphabet(nextAlphabet);onParameterChange("fontSize", nextDefault);diff --git a/frontend/editor/src/core/services/pdfProcessingService.ts b/frontend/editor/src/core/services/pdfProcessingService.tsindex 9ccc748946..93ca93d96a 100644--- a/frontend/editor/src/core/services/pdfProcessingService.ts+++ b/frontend/editor/src/core/services/pdfProcessingService.ts@@ -1,5 +1,6 @@import { ProcessedFile, ProcessingState, PDFPage } from "@app/types/processing";import { ProcessingCache } from "@app/services/processingCache";+import { ProcessingErrorHandler } from "@app/services/processingErrorHandler";import { pdfWorkerManager } from "@app/services/pdfWorkerManager";import { createQuickKey } from "@app/types/fileContext";@@ -82,9 +83,7 @@ export class PDFProcessingService {} catch (error) {console.error("Processing failed for", file.name, ":", error);state.status = "error";- state.error = (- error instanceof Error ? error.message : "Unknown error"- ) as any;+ state.error = ProcessingErrorHandler.createProcessingError(error);this.notifyListeners();// Remove failed processing after delaydiff --git a/frontend/editor/src/core/services/zipFileService.ts b/frontend/editor/src/core/services/zipFileService.tsindex 8ce3d90ad5..3e57237cfc 100644--- a/frontend/editor/src/core/services/zipFileService.ts+++ b/frontend/editor/src/core/services/zipFileService.ts@@ -13,7 +13,7 @@ interface CompressedObject {}const getData = (zipEntry: JSZipObject): CompressedObject | undefined => {- return (zipEntry as any)._data as CompressedObject;+ return (zipEntry as JSZipObject & { _data: CompressedObject })._data;};export interface ZipExtractionResult {@@ -236,7 +236,7 @@ export class ZipFileService {// Create File objectconst extractedFile = new File(- [content as any],+ [content as Uint8Array<ArrayBuffer>],this.sanitizeFilename(filename),{type: "application/pdf",diff --git a/frontend/oxlint.config.ts b/frontend/oxlint.config.tsindex 314bc3178e..c8c7ce711c 100644--- a/frontend/oxlint.config.ts+++ b/frontend/oxlint.config.ts@@ -74,14 +74,10 @@ const modernGlobals: OxlintGlobals = {// Folders not yet conformant to the stricter no-explicit-any ruleconst noExplicitAnyExcludes = [- "editor/src/core/components/shared/FilePickerModal.tsx","editor/src/core/components/shared/config/configSections/*.{js,mjs,jsx,ts,tsx}",- "editor/src/core/components/tools/addStamp/*.{js,mjs,jsx,ts,tsx}","editor/src/core/components/viewer/*.{js,mjs,jsx,ts,tsx}","editor/src/core/contexts/*.{js,mjs,jsx,ts,tsx}","editor/src/core/hooks/*.{js,mjs,jsx,ts,tsx}",- "editor/src/core/services/pdfProcessingService.ts",- "editor/src/core/services/zipFileService.ts","editor/src/core/tools/annotate/useAnnotationSelection.ts","editor/src/core/types/*.{js,mjs,jsx,ts,tsx}","editor/src/core/utils/*.{js,mjs,jsx,ts,tsx}",