Skip to content

Commit 408f9ef

Browse files
authored
Fix any type usages in frontend code (#7326)
# Description of Changes Continued effort towards removing all uses of the `any` type in our frontend code. This PR fixes 10 more folders and removes them from the exclude list. All of them were really simple fixes.
1 parent cff6549 commit 408f9ef

13 files changed

Lines changed: 41 additions & 36 deletions

File tree

frontend/editor/src/core/components/pageEditor/commands/pageCommands.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ export class InsertFilesCommand extends DOMCommand {
686686
private insertedPages: PDFPage[] = [];
687687
private originalDocument: PDFDocument | null = null;
688688
private fileDataMap = new Map<FileId, ArrayBuffer>(); // Store file data for thumbnail generation
689-
private originalProcessedFile: any = null; // Store original ProcessedFile for undo
690689
private insertedFileMap = new Map<FileId, File>(); // Store inserted files for export
691690

692691
constructor(

frontend/editor/src/core/components/pageEditor/hooks/useEditorCommands.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useRef } from "react";
33
import {
44
BulkRotateCommand,
55
DeletePagesCommand,
6+
DOMCommand,
67
PageBreakCommand,
78
ReorderPagesCommand,
89
SplitCommand,
@@ -24,7 +25,7 @@ interface UsePageEditorCommandsParams {
2425
selectedPageIds: string[];
2526
setSelectedPageIds: (ids: string[]) => void;
2627
getPageNumbersFromIds: (pageIds: string[]) => number[];
27-
executeCommandWithTracking: (command: any) => void;
28+
executeCommandWithTracking: (command: DOMCommand) => void;
2829
updateFileOrderFromPages: (pages: PDFPage[]) => void;
2930
actions: FileActions;
3031
selectors: FileSelectors;
@@ -145,10 +146,8 @@ export const usePageEditorCommands = ({
145146
[executeCommandWithTracking, setSplitPositions],
146147
);
147148

148-
const executeCommand = useCallback((command: any) => {
149-
if (command && typeof command.execute === "function") {
150-
command.execute();
151-
}
149+
const executeCommand = useCallback((command: { execute: () => void }) => {
150+
command.execute();
152151
}, []);
153152

154153
const handleRotate = useCallback(

frontend/editor/src/core/components/pageEditor/hooks/useUndoManagerState.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { useCallback, useEffect, useRef, useState } from "react";
22

3-
import { UndoManager } from "@app/components/pageEditor/commands/pageCommands";
3+
import {
4+
DOMCommand,
5+
UndoManager,
6+
} from "@app/components/pageEditor/commands/pageCommands";
47

58
interface UseUndoManagerStateParams {
69
setHasUnsavedChanges: (dirty: boolean) => void;
@@ -29,7 +32,7 @@ export const useUndoManagerState = ({
2932
}, [updateUndoRedoState]);
3033

3134
const executeCommandWithTracking = useCallback(
32-
(command: any) => {
35+
(command: DOMCommand) => {
3336
undoManagerRef.current.executeCommand(command);
3437
setHasUnsavedChanges(true);
3538
},

frontend/editor/src/core/components/shared/config/SettingsSearchBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const SettingsSearchBar: React.FC<SettingsSearchBarProps> = ({
138138
const translationPrefixes = getTranslationPrefixesForNavKey(item.key);
139139
const translationContent = translationPrefixes.flatMap((prefix) =>
140140
flattenTranslationStrings(
141-
t(prefix, { returnObjects: true, defaultValue: {} } as any),
141+
t(prefix, { returnObjects: true, defaultValue: {} }),
142142
),
143143
);
144144

frontend/editor/src/core/components/shared/pageEditor/useFileItemDragDrop.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ export const useFileItemDragDrop = ({
111111
if (!element) return;
112112

113113
const rect = element.getBoundingClientRect();
114-
const clientY =
115-
(source as any).element?.getBoundingClientRect().top || 0;
114+
const clientY = source.element?.getBoundingClientRect().top || 0;
116115
const midpoint = rect.top + rect.height / 2;
117116

118117
setDropPosition(clientY < midpoint ? "below" : "above");
@@ -121,7 +120,10 @@ export const useFileItemDragDrop = ({
121120
setIsDragOver(false);
122121
const dropPos = dropPositionRef.current;
123122
setDropPosition("below");
124-
const sourceData = source.data as any;
123+
const sourceData = source.data as {
124+
type?: string;
125+
fromIndex?: number;
126+
};
125127
if (sourceData?.type === "file-item") {
126128
const fromIndex = sourceData.fromIndex as number;
127129
let toIndex = indexRef.current;

frontend/editor/src/core/components/tools/bookletImposition/BookletImpositionSettings.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import ButtonSelector from "@app/components/shared/ButtonSelector";
1414

1515
interface BookletImpositionSettingsProps {
1616
parameters: BookletImpositionParameters;
17-
onParameterChange: (
18-
key: keyof BookletImpositionParameters,
19-
value: any,
17+
onParameterChange: <K extends keyof BookletImpositionParameters>(
18+
key: K,
19+
value: BookletImpositionParameters[K],
2020
) => void;
2121
disabled?: boolean;
2222
}
@@ -214,7 +214,10 @@ const BookletImpositionSettings = ({
214214
)}
215215
value={parameters.gutterSize}
216216
onChange={(value) =>
217-
onParameterChange("gutterSize", value || 12)
217+
onParameterChange(
218+
"gutterSize",
219+
typeof value === "number" ? value : 12,
220+
)
218221
}
219222
min={6}
220223
max={72}

frontend/editor/src/core/components/tools/shared/ToolWorkflowTitle.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React from "react";
22
import { Flex, Text, Divider } from "@mantine/core";
33
import LocalIcon from "@app/components/shared/LocalIcon";
44
import { Tooltip } from "@app/components/shared/Tooltip";
5+
import { TooltipTip } from "@app/types/tips";
56

67
export interface ToolWorkflowTitleProps {
78
title: string;
89
description?: string;
910
tooltip?: {
1011
content?: React.ReactNode;
11-
tips?: any[];
12+
tips?: TooltipTip[];
1213
header?: {
1314
title: string;
1415
logo?: React.ReactNode;

frontend/editor/src/core/components/tools/shared/renderToolButtons.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { Box } from "@mantine/core";
22
import ToolButton from "@app/components/tools/toolPicker/ToolButton";
33
import SubcategoryHeader from "@app/components/tools/shared/SubcategoryHeader";
44

5-
import { getSubcategoryLabel } from "@app/data/toolsTaxonomy";
5+
import {
6+
getSubcategoryLabel,
7+
type ToolRegistryEntry,
8+
} from "@app/data/toolsTaxonomy";
69
import { TFunction } from "i18next";
710
import { SubcategoryGroup } from "@app/hooks/useToolSections";
811
import { ToolId } from "@app/types/toolId";
@@ -15,7 +18,10 @@ export const renderToolButtons = (
1518
onSelect: (id: ToolId) => void,
1619
showSubcategoryHeader: boolean = true,
1720
disableNavigation: boolean = false,
18-
searchResults?: Array<{ item: [string, any]; matchedText?: string }>,
21+
searchResults?: Array<{
22+
item: [ToolId, ToolRegistryEntry];
23+
matchedText?: string;
24+
}>,
1925
hasStars: boolean = false,
2026
) => {
2127
// Create a map of matched text for quick lookup

frontend/editor/src/core/hooks/signing/useSigningSessionController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback, useEffect, useRef, useState } from "react";
22
import { useTranslation } from "react-i18next";
3+
import { isAxiosError } from "axios";
34
import apiClient from "@app/services/apiClient";
45
import { alert } from "@app/components/toast";
56
import { fileStorage } from "@app/services/fileStorage";
@@ -333,8 +334,8 @@ export function useSigningSessionController(enabled: boolean) {
333334
pdfFile = new File([pdfResponse.data], session.documentName, {
334335
type: "application/pdf",
335336
});
336-
} catch (pdfError: any) {
337-
if (pdfError?.response?.status === 404) {
337+
} catch (pdfError) {
338+
if (isAxiosError(pdfError) && pdfError.response?.status === 404) {
338339
alert({
339340
alertType: "warning",
340341
title: t("certSign.sessions.pdfNotReady", "PDF Not Ready"),

frontend/editor/src/core/hooks/tools/adjustContrast/useAdjustContrastOperation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import { pdfWorkerManager } from "@app/services/pdfWorkerManager";
1313
import { createFileFromApiResponse } from "@app/utils/fileResponseUtils";
1414
import { getPdfiumModule, saveRawDocument } from "@app/services/pdfiumService";
1515
import { copyRgbaToBgraHeap } from "@app/utils/pdfiumBitmapUtils";
16+
import type { PDFDocumentProxy } from "pdfjs-dist";
1617

1718
async function renderPdfPageToCanvas(
18-
pdf: any,
19+
pdf: PDFDocumentProxy,
1920
pageNumber: number,
2021
scale: number,
2122
): Promise<HTMLCanvasElement> {
@@ -26,7 +27,7 @@ async function renderPdfPageToCanvas(
2627
canvas.height = viewport.height;
2728
const ctx = canvas.getContext("2d");
2829
if (!ctx) throw new Error("Canvas 2D context unavailable");
29-
await page.render({ canvasContext: ctx, viewport }).promise;
30+
await page.render({ canvasContext: ctx, canvas, viewport }).promise;
3031
return canvas;
3132
}
3233

0 commit comments

Comments
 (0)