Skip to content

Commit 7b413ce

Browse files
authored
Fix any types in frontend code (#7817)
# Description of Changes Continued work towards removing all uses of the `any` type in frontend code.
1 parent 153da23 commit 7b413ce

9 files changed

Lines changed: 70 additions & 47 deletions

File tree

frontend/editor/src/core/components/shared/FilePickerModal.stories.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import type { Meta, StoryObj } from "@storybook/react-vite";
22
import FilePickerModal from "@app/components/shared/FilePickerModal";
3+
import type { FileId } from "@app/types/file";
34

45
const mockStoredFiles = [
5-
{ id: "file-1", name: "invoice.pdf", size: 245_000, thumbnail: null },
66
{
7-
id: "file-2",
7+
id: "file-1" as FileId,
8+
name: "invoice.pdf",
9+
size: 245_000,
10+
},
11+
{
12+
id: "file-2" as FileId,
813
name: "contract-draft.pdf",
914
size: 1_240_000,
10-
thumbnail: null,
1115
},
12-
{ id: "file-3", name: "scanned-form.pdf", size: 3_400_000, thumbnail: null },
16+
{
17+
id: "file-3" as FileId,
18+
name: "scanned-form.pdf",
19+
size: 3_400_000,
20+
},
1321
];
1422

1523
const meta = {

frontend/editor/src/core/components/shared/FilePickerModal.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ import { Button } from "@app/ui/Button";
1414
import { useTranslation } from "react-i18next";
1515
import DocumentThumbnail from "@app/components/shared/filePreview/DocumentThumbnail";
1616
import { FileId } from "@app/types/file";
17+
import type { StoredStirlingFileRecord } from "@app/services/fileStorage";
1718
import { useFileActionTerminology } from "@app/hooks/useFileActionTerminology";
1819

20+
type StoredFileItem = Partial<StoredStirlingFileRecord> & {
21+
id: FileId;
22+
file?: File;
23+
arrayBuffer?: () => Promise<ArrayBuffer>;
24+
processedFile?: { isEncrypted?: boolean };
25+
};
26+
1927
interface FilePickerModalProps {
2028
opened: boolean;
2129
onClose: () => void;
22-
storedFiles: any[]; // Files from storage (various formats supported)
30+
storedFiles: StoredFileItem[];
2331
onSelectFiles: (selectedFiles: File[]) => void;
2432
}
2533

@@ -84,7 +92,7 @@ const FilePickerModal = ({
8492
const blob = new Blob([arrayBuffer], {
8593
type: fileItem.type || "application/pdf",
8694
});
87-
return new File([blob], fileItem.name, {
95+
return new File([blob], fileItem.name ?? "", {
8896
type: fileItem.type || "application/pdf",
8997
lastModified: fileItem.lastModified || Date.now(),
9098
});
@@ -95,7 +103,7 @@ const FilePickerModal = ({
95103
const blob = new Blob([fileItem.data], {
96104
type: fileItem.type || "application/pdf",
97105
});
98-
return new File([blob], fileItem.name, {
106+
return new File([blob], fileItem.name ?? "", {
99107
type: fileItem.type || "application/pdf",
100108
lastModified: fileItem.lastModified || Date.now(),
101109
});
@@ -211,7 +219,7 @@ const FilePickerModal = ({
211219
}}
212220
>
213221
<DocumentThumbnail
214-
file={file}
222+
file={file.file ?? null}
215223
thumbnail={
216224
file.processedFile?.isEncrypted
217225
? undefined

frontend/editor/src/core/components/tools/addStamp/StampPositionFormattingSettings.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ const StampPositionFormattingSettings = ({
6060
onClick={() => {
6161
onParameterChange("position", idx);
6262
// Ensure we're using grid positioning, not custom overrides
63-
onParameterChange("overrideX", -1 as any);
64-
onParameterChange("overrideY", -1 as any);
63+
onParameterChange("overrideX", -1);
64+
onParameterChange("overrideY", -1);
6565
}}
6666
disabled={disabled}
6767
style={{
@@ -257,7 +257,10 @@ const StampPositionFormattingSettings = ({
257257
label={t("AddStampRequest.margin", "Margin")}
258258
value={parameters.customMargin}
259259
onChange={(v) =>
260-
onParameterChange("customMargin", (v as any) || "medium")
260+
onParameterChange(
261+
"customMargin",
262+
(v as AddStampParameters["customMargin"]) || "medium",
263+
)
261264
}
262265
data={[
263266
{ value: "small", label: t("margin.small", "Small") },

frontend/editor/src/core/components/tools/addStamp/StampPreview.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ export default function StampPreview({
172172
bottomPx: number;
173173
} | null>(null);
174174
useEffect(() => {
175-
const itemStyle = style.item as any;
175+
const itemStyle = style.item;
176176
if (!itemStyle || containerSize.width <= 0 || containerSize.height <= 0)
177177
return;
178178

179-
const parse = (v: any) => parseFloat(String(v).replace("px", "")) || 0;
179+
const parse = (v: string | number | undefined) =>
180+
parseFloat(String(v).replace("px", "")) || 0;
180181
const leftPx = parse(itemStyle.left);
181182
const bottomPx = parse(itemStyle.bottom);
182183
const widthPx = parse(itemStyle.width);
@@ -208,8 +209,8 @@ export default function StampPreview({
208209
const newLeftPts = Math.max(0, Math.min(maxLeftPx, newLeftPx)) / scaleX;
209210
const newBottomPts =
210211
Math.max(0, Math.min(maxBottomPx, newBottomPx)) / scaleY;
211-
onParameterChange("overrideX", newLeftPts as any);
212-
onParameterChange("overrideY", newBottomPts as any);
212+
onParameterChange("overrideX", newLeftPts);
213+
onParameterChange("overrideY", newBottomPts);
213214
}
214215

215216
prevDimsRef.current = {
@@ -249,7 +250,7 @@ export default function StampPreview({
249250
if (pageWidth <= 0 || pageHeight <= 0) return;
250251

251252
// Recompute current x,y from style (so that we start from visual position)
252-
const itemStyle = style.item as any;
253+
const itemStyle = style.item;
253254
const leftPx = parseFloat(String(itemStyle.left).replace("px", "")) || 0;
254255
const bottomPx =
255256
parseFloat(String(itemStyle.bottom).replace("px", "")) || 0;
@@ -265,11 +266,11 @@ export default function StampPreview({
265266
const maxBottomPx = Math.max(0, pageHeight - heightPx);
266267
onParameterChange(
267268
"overrideX",
268-
(Math.max(0, Math.min(maxLeftPx, leftPx)) / scaleX) as any,
269+
Math.max(0, Math.min(maxLeftPx, leftPx)) / scaleX,
269270
);
270271
onParameterChange(
271272
"overrideY",
272-
(Math.max(0, Math.min(maxBottomPx, bottomPx)) / scaleY) as any,
273+
Math.max(0, Math.min(maxBottomPx, bottomPx)) / scaleY,
273274
);
274275
}
275276
};
@@ -281,7 +282,7 @@ export default function StampPreview({
281282
e.preventDefault();
282283
ensureOverrides();
283284

284-
const item = style.item as any;
285+
const item = style.item;
285286
const left = parseFloat(String(item.left).replace("px", "")) || 0;
286287
const bottom = parseFloat(String(item.bottom).replace("px", "")) || 0;
287288
const width =
@@ -336,8 +337,8 @@ export default function StampPreview({
336337
const scaleY = containerSize.height / heightPts;
337338
const newLeftPts = newLeftPx / scaleX;
338339
const newBottomPts = newBottomPx / scaleY;
339-
onParameterChange("overrideX", newLeftPts as any);
340-
onParameterChange("overrideY", newBottomPts as any);
340+
onParameterChange("overrideX", newLeftPts);
341+
onParameterChange("overrideY", newBottomPts);
341342
}
342343

343344
if (drag.type === "resize") {
@@ -346,13 +347,13 @@ export default function StampPreview({
346347
const scaleY = containerSize.height / heightPts;
347348
const newHeightPx = Math.max(1, drag.initHeight + (y - drag.startY));
348349
const newHeightPts = newHeightPx / scaleY;
349-
onParameterChange("fontSize", newHeightPts as any);
350+
onParameterChange("fontSize", newHeightPts);
350351
}
351352

352353
if (drag.type === "rotate") {
353354
const angle =
354355
Math.atan2(y - drag.centerY, x - drag.centerX) * (180 / Math.PI);
355-
onParameterChange("rotation", angle as any);
356+
onParameterChange("rotation", angle);
356357
}
357358
};
358359

@@ -441,9 +442,12 @@ export default function StampPreview({
441442
className={`${styles.gridTile} ${selected || hoverTile === idx ? styles.gridTileSelected : ""} ${hoverTile === idx ? styles.gridTileHovered : ""}`}
442443
onClick={() => {
443444
// Clear overrides to use grid positioning and set position
444-
onParameterChange("overrideX", -1 as any);
445-
onParameterChange("overrideY", -1 as any);
446-
onParameterChange("position", idx as any);
445+
onParameterChange("overrideX", -1);
446+
onParameterChange("overrideY", -1);
447+
onParameterChange(
448+
"position",
449+
idx as AddStampParameters["position"],
450+
);
447451
}}
448452
onMouseEnter={() => setHoverTile(idx)}
449453
onMouseLeave={() => setHoverTile(null)}

frontend/editor/src/core/components/tools/addStamp/StampPreviewUtils.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { CSSProperties } from "react";
12
import type { AddStampParameters } from "@app/components/tools/addStamp/useAddStampParameters";
23

34
export type ContainerSize = { width: number; height: number };
@@ -54,7 +55,10 @@ export const getFirstSelectedPage = (input: string): number => {
5455
return 1;
5556
};
5657

57-
export type StampPreviewStyle = { container: any; item: any };
58+
export type StampPreviewStyle = {
59+
container: CSSProperties;
60+
item: CSSProperties;
61+
};
5862

5963
// Unified per-alphabet preview adjustments
6064
export type Alphabet =
@@ -117,10 +121,10 @@ export const ALPHABET_PREVIEW_TWEAKS: Record<Alphabet, AlphabetTweaks> = {
117121
},
118122
};
119123
export const getAlphabetPreviewScale = (alphabet: string): number =>
120-
(ALPHABET_PREVIEW_TWEAKS as any)[alphabet]?.scale ?? 1.0;
124+
ALPHABET_PREVIEW_TWEAKS[alphabet as Alphabet]?.scale ?? 1.0;
121125

122126
export const getDefaultFontSizeForAlphabet = (alphabet: string): number => {
123-
return (ALPHABET_PREVIEW_TWEAKS as any)[alphabet]?.defaultFontSize ?? 80;
127+
return ALPHABET_PREVIEW_TWEAKS[alphabet as Alphabet]?.defaultFontSize ?? 80;
124128
};
125129

126130
export function computeStampPreviewStyle(
@@ -138,8 +142,7 @@ export function computeStampPreviewStyle(
138142
const heightPts = pageSize?.heightPts ?? 841.89; // A4 height at 72 DPI
139143
const scaleX = pageWidthPx / widthPts;
140144
const scaleY = pageHeightPx / heightPts;
141-
if (pageWidthPx <= 0 || pageHeightPx <= 0)
142-
return { item: {}, container: {} } as any;
145+
if (pageWidthPx <= 0 || pageHeightPx <= 0) return { item: {}, container: {} };
143146

144147
const marginPts =
145148
((widthPts + heightPts) / 2) *
@@ -215,8 +218,7 @@ export function computeStampPreviewStyle(
215218
const heightForY =
216219
parameters.stampType === "text"
217220
? heightPtsContent *
218-
((ALPHABET_PREVIEW_TWEAKS as any)[parameters.alphabet]
219-
?.capHeightRatio ?? 0.7)
221+
(ALPHABET_PREVIEW_TWEAKS[parameters.alphabet]?.capHeightRatio ?? 0.7)
220222
: heightPtsContent;
221223
switch (Math.floor((position - 1) / 3)) {
222224
case 0: // Top
@@ -241,7 +243,7 @@ export function computeStampPreviewStyle(
241243
getComputedStyle(document.documentElement).fontSize || "16",
242244
) || 16;
243245
const rowIndex = Math.floor((position - 1) / 3); // 0 top, 1 middle, 2 bottom
244-
const offsets = (ALPHABET_PREVIEW_TWEAKS as any)[parameters.alphabet]
246+
const offsets = ALPHABET_PREVIEW_TWEAKS[parameters.alphabet]
245247
?.rowOffsetRem ?? [0, 0, 0];
246248
const offsetRem = offsets[rowIndex] ?? 0;
247249
yPx += offsetRem * rootFontSizePx;
@@ -297,8 +299,7 @@ export function computeStampPreviewStyle(
297299
display: "flex",
298300
flexDirection: "column",
299301
justifyContent: "flex-start",
300-
lineHeight:
301-
(ALPHABET_PREVIEW_TWEAKS as any)[parameters.alphabet]?.lineHeight ?? 1,
302+
lineHeight: ALPHABET_PREVIEW_TWEAKS[parameters.alphabet]?.lineHeight ?? 1,
302303
alignItems,
303304
cursor: showQuickGrid ? "default" : "move",
304305
pointerEvents: showQuickGrid ? "none" : "auto",

frontend/editor/src/core/components/tools/addStamp/StampSetupSettings.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ const StampSetupSettings = ({
265265
const template = STAMP_TEMPLATES.find((t) => t.id === value);
266266
if (template) {
267267
onParameterChange("stampText", template.text);
268-
onParameterChange("position", template.position as any);
268+
onParameterChange(
269+
"position",
270+
template.position as AddStampParameters["position"],
271+
);
269272
}
270273
}}
271274
clearable
@@ -640,7 +643,8 @@ const StampSetupSettings = ({
640643
label={t("AddStampRequest.alphabet", "Alphabet")}
641644
value={parameters.alphabet}
642645
onChange={(v) => {
643-
const nextAlphabet = (v as any) || "roman";
646+
const nextAlphabet =
647+
(v as AddStampParameters["alphabet"]) || "roman";
644648
onParameterChange("alphabet", nextAlphabet);
645649
const nextDefault = getDefaultFontSizeForAlphabet(nextAlphabet);
646650
onParameterChange("fontSize", nextDefault);

frontend/editor/src/core/services/pdfProcessingService.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ProcessedFile, ProcessingState, PDFPage } from "@app/types/processing";
22
import { ProcessingCache } from "@app/services/processingCache";
3+
import { ProcessingErrorHandler } from "@app/services/processingErrorHandler";
34
import { pdfWorkerManager } from "@app/services/pdfWorkerManager";
45
import { createQuickKey } from "@app/types/fileContext";
56

@@ -82,9 +83,7 @@ export class PDFProcessingService {
8283
} catch (error) {
8384
console.error("Processing failed for", file.name, ":", error);
8485
state.status = "error";
85-
state.error = (
86-
error instanceof Error ? error.message : "Unknown error"
87-
) as any;
86+
state.error = ProcessingErrorHandler.createProcessingError(error);
8887
this.notifyListeners();
8988

9089
// Remove failed processing after delay

frontend/editor/src/core/services/zipFileService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface CompressedObject {
1313
}
1414

1515
const getData = (zipEntry: JSZipObject): CompressedObject | undefined => {
16-
return (zipEntry as any)._data as CompressedObject;
16+
return (zipEntry as JSZipObject & { _data: CompressedObject })._data;
1717
};
1818

1919
export interface ZipExtractionResult {
@@ -236,7 +236,7 @@ export class ZipFileService {
236236

237237
// Create File object
238238
const extractedFile = new File(
239-
[content as any],
239+
[content as Uint8Array<ArrayBuffer>],
240240
this.sanitizeFilename(filename),
241241
{
242242
type: "application/pdf",

frontend/oxlint.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,10 @@ const modernGlobals: OxlintGlobals = {
7474

7575
// Folders not yet conformant to the stricter no-explicit-any rule
7676
const noExplicitAnyExcludes = [
77-
"editor/src/core/components/shared/FilePickerModal.tsx",
7877
"editor/src/core/components/shared/config/configSections/*.{js,mjs,jsx,ts,tsx}",
79-
"editor/src/core/components/tools/addStamp/*.{js,mjs,jsx,ts,tsx}",
8078
"editor/src/core/components/viewer/*.{js,mjs,jsx,ts,tsx}",
8179
"editor/src/core/contexts/*.{js,mjs,jsx,ts,tsx}",
8280
"editor/src/core/hooks/*.{js,mjs,jsx,ts,tsx}",
83-
"editor/src/core/services/pdfProcessingService.ts",
84-
"editor/src/core/services/zipFileService.ts",
8581
"editor/src/core/tools/annotate/useAnnotationSelection.ts",
8682
"editor/src/core/types/*.{js,mjs,jsx,ts,tsx}",
8783
"editor/src/core/utils/*.{js,mjs,jsx,ts,tsx}",

0 commit comments

Comments
 (0)