Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Fix more `any` types in frontend code (#7825)

James Brunton21b53c2055f3
diff --git a/frontend/editor/src/core/components/shared/FileSidebar.tsx b/frontend/editor/src/core/components/shared/FileSidebar.tsx
index ca737e746d..bb9afc5dc9 100644
--- a/frontend/editor/src/core/components/shared/FileSidebar.tsx
+++ b/frontend/editor/src/core/components/shared/FileSidebar.tsx
@@ -39,6 +39,7 @@ import UploadFileIcon from "@mui/icons-material/UploadFile";
import AddIcon from "@mui/icons-material/Add";
import OpenInFullIcon from "@mui/icons-material/OpenInFull";
import type { FileId } from "@app/types/file";
+import type { WatchedFolderViewData } from "@app/types/watchedFolders";
import { FileItem } from "@app/components/shared/FileSidebarFileItem";
import { useLabelName } from "@app/data/labelDisplay";
import { useClassificationEnabled } from "@app/hooks/useClassificationEnabled";
@@ -192,9 +193,12 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
const isWatchedFoldersActive =
currentWorkbench === WATCHED_FOLDER_WORKBENCH_ID;
// The folder currently open in the Watched Folders view (null = folder list/home).
- const activeWatchedFolderId = (customWorkbenchViews.find(
+ const watchedFolderView = customWorkbenchViews.find(
(v) => v.id === WATCHED_FOLDER_VIEW_ID,
- )?.data?.folderId ?? null) as string | null;
+ );
+ const activeWatchedFolderId =
+ (watchedFolderView?.data as WatchedFolderViewData | undefined)
+ ?.folderId ?? null;
// fileId → folderId[] across all watch folders. In the Watched Folders view the
// sidebar tick reflects "already in the open folder" instead of workbench
// membership (which is meaningless there - a click sends to the folder, not
diff --git a/frontend/editor/src/core/components/shared/config/configSections/Overview.tsx b/frontend/editor/src/core/components/shared/config/configSections/Overview.tsx
index 2c0e28efdc..a25b72141b 100644
--- a/frontend/editor/src/core/components/shared/config/configSections/Overview.tsx
+++ b/frontend/editor/src/core/components/shared/config/configSections/Overview.tsx
@@ -8,7 +8,7 @@ const Overview: React.FC = () => {
const { t } = useTranslation();
const { config, loading, error } = useAppConfig();
- const renderConfigSection = (title: string, data: any) => {
+ const renderConfigSection = (title: string, data: unknown) => {
if (!data || typeof data !== "object") return null;
return (
@@ -17,22 +17,24 @@ const Overview: React.FC = () => {
{title}
</Text>
<Stack gap="xs" pl="md">
- {Object.entries(data).map(([key, value]) => (
- <Group key={key} wrap="nowrap" align="flex-start">
- <Text size="sm" w={150} style={{ flexShrink: 0 }} c="dimmed">
- {key}:
- </Text>
- {typeof value === "boolean" ? (
- <Badge color={value ? "green" : "red"} size="sm">
- {value ? "true" : "false"}
- </Badge>
- ) : typeof value === "object" ? (
- <Code block>{JSON.stringify(value, null, 2)}</Code>
- ) : (
- String(value) || "null"
- )}
- </Group>
- ))}
+ {Object.entries(data as Record<string, unknown>).map(
+ ([key, value]) => (
+ <Group key={key} wrap="nowrap" align="flex-start">
+ <Text size="sm" w={150} style={{ flexShrink: 0 }} c="dimmed">
+ {key}:
+ </Text>
+ {typeof value === "boolean" ? (
+ <Badge color={value ? "green" : "red"} size="sm">
+ {value ? "true" : "false"}
+ </Badge>
+ ) : typeof value === "object" ? (
+ <Code block>{JSON.stringify(value, null, 2)}</Code>
+ ) : (
+ String(value) || "null"
+ )}
+ </Group>
+ ),
+ )}
</Stack>
</Stack>
);
diff --git a/frontend/editor/src/core/components/shared/config/configSections/providerDefinitions.ts b/frontend/editor/src/core/components/shared/config/configSections/providerDefinitions.ts
index 72dc675f8f..98d2b3844c 100644
--- a/frontend/editor/src/core/components/shared/config/configSections/providerDefinitions.ts
+++ b/frontend/editor/src/core/components/shared/config/configSections/providerDefinitions.ts
@@ -3,13 +3,17 @@ import { oauthIconUrl } from "@app/auth/ui/oauthIcons";
export type ProviderType = "oauth2" | "saml2" | "telegram" | "googledrive";
+/** Value of a provider field, keyed by its `type`: text/password/textarea -> string,
+ * number -> number, switch -> boolean, tags -> string[]. */
+export type FieldValue = string | number | boolean | string[];
+
export interface ProviderField {
key: string;
type: "text" | "password" | "switch" | "textarea" | "number" | "tags";
label: string;
description: string;
placeholder?: string;
- defaultValue?: any;
+ defaultValue?: FieldValue;
}
export interface Provider {
diff --git a/frontend/editor/src/core/contexts/ToolWorkflowContext.tsx b/frontend/editor/src/core/contexts/ToolWorkflowContext.tsx
index b4ef874184..df75ec1808 100644
--- a/frontend/editor/src/core/contexts/ToolWorkflowContext.tsx
+++ b/frontend/editor/src/core/contexts/ToolWorkflowContext.tsx
@@ -46,18 +46,20 @@ import { useToolRegistry } from "@app/contexts/ToolRegistryContext";
// Types and reducer/state moved to './toolWorkflow/state'
// Context value interface
-export interface CustomWorkbenchViewRegistration {
+export interface CustomWorkbenchViewRegistration<T = unknown> {
id: string;
workbenchId: WorkbenchType;
label: string;
icon?: React.ReactNode;
- component: React.ComponentType<{ data: any }>;
+ component: React.ComponentType<{ data: T }>;
hideTopControls?: boolean;
hideToolPanel?: boolean;
}
-export interface CustomWorkbenchViewInstance extends CustomWorkbenchViewRegistration {
- data: any;
+export interface CustomWorkbenchViewInstance<
+ T = unknown,
+> extends CustomWorkbenchViewRegistration<T> {
+ data: T;
}
interface ToolWorkflowContextValue extends ToolWorkflowState {
@@ -107,22 +109,28 @@ interface ToolWorkflowContextValue extends ToolWorkflowState {
isFavorite: (toolId: ToolId) => boolean;
customWorkbenchViews: CustomWorkbenchViewInstance[];
- registerCustomWorkbenchView: (view: CustomWorkbenchViewRegistration) => void;
+ registerCustomWorkbenchView: <T>(
+ view: CustomWorkbenchViewRegistration<T>,
+ ) => void;
unregisterCustomWorkbenchView: (id: string) => void;
- setCustomWorkbenchViewData: (id: string, data: any) => void;
+ setCustomWorkbenchViewData: <T>(
+ id: string,
+ data: T | ((prev: T) => T),
+ ) => void;
clearCustomWorkbenchViewData: (id: string) => void;
}
// Ensure a single context instance across HMR to avoid provider/consumer mismatches
const __GLOBAL_CONTEXT_KEY__ = "__ToolWorkflowContext__";
-const existingContext = (globalThis as any)[__GLOBAL_CONTEXT_KEY__] as
- | React.Context<ToolWorkflowContextValue | undefined>
- | undefined;
+const existingContext = (globalThis as Record<string, unknown>)[
+ __GLOBAL_CONTEXT_KEY__
+] as React.Context<ToolWorkflowContextValue | undefined> | undefined;
const ToolWorkflowContext =
existingContext ??
createContext<ToolWorkflowContextValue | undefined>(undefined);
if (!existingContext) {
- (globalThis as any)[__GLOBAL_CONTEXT_KEY__] = ToolWorkflowContext;
+ (globalThis as Record<string, unknown>)[__GLOBAL_CONTEXT_KEY__] =
+ ToolWorkflowContext;
}
/**
@@ -187,7 +195,7 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) {
Record<string, CustomWorkbenchViewRegistration>
>({});
const [customViewData, setCustomViewData] = React.useState<
- Record<string, any>
+ Record<string, unknown>
>({});
// Navigation actions and state are available since we're inside NavigationProvider
@@ -259,8 +267,13 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) {
}, []);
const registerCustomWorkbenchView = useCallback(
- (view: CustomWorkbenchViewRegistration) => {
- setCustomViewRegistry((prev) => ({ ...prev, [view.id]: view }));
+ <T,>(view: CustomWorkbenchViewRegistration<T>) => {
+ setCustomViewRegistry((prev) => ({
+ ...prev,
+ // Type-erase the view's data shape for uniform storage; the render site
+ // hands the opaque data back to this same component to narrow.
+ [view.id]: view as CustomWorkbenchViewRegistration,
+ }));
},
[],
);
@@ -300,12 +313,12 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) {
);
const setCustomWorkbenchViewData = useCallback(
- (id: string, dataOrUpdater: any | ((prev: any) => any)) => {
+ <T,>(id: string, dataOrUpdater: T | ((prev: T) => T)) => {
setCustomViewData((prev) => {
- const currentData = prev[id];
+ const currentData = prev[id] as T;
const newData =
typeof dataOrUpdater === "function"
- ? dataOrUpdater(currentData)
+ ? (dataOrUpdater as (prev: T) => T)(currentData)
: dataOrUpdater;
return { ...prev, [id]: newData };
});
diff --git a/frontend/editor/src/core/tools/ShowJS.tsx b/frontend/editor/src/core/tools/ShowJS.tsx
index f41b31f43b..7ed5b02e2c 100644
--- a/frontend/editor/src/core/tools/ShowJS.tsx
+++ b/frontend/editor/src/core/tools/ShowJS.tsx
@@ -53,7 +53,7 @@ const ShowJS = (props: BaseToolProps) => {
workbenchId: WORKBENCH_ID,
label: t("showJS.view.title", "JavaScript"),
icon: viewIcon,
- component: ({ data }) => <ShowJSView data={data} />,
+ component: ShowJSView,
});
return () => {
diff --git a/frontend/editor/src/core/types/fileIdSafety.d.ts b/frontend/editor/src/core/types/fileIdSafety.d.ts
index dc4c77896a..2283919cc4 100644
--- a/frontend/editor/src/core/types/fileIdSafety.d.ts
+++ b/frontend/editor/src/core/types/fileIdSafety.d.ts
@@ -7,18 +7,17 @@ import { FileId, StirlingFile } from "@app/types/fileContext";
declare global {
namespace FileIdSafety {
// Mark functions that should never accept file.name as parameters
- type SafeFileIdFunction<T extends (...args: any[]) => any> = T extends (
- ...args: infer P
- ) => infer _R
- ? P extends readonly [string, ...any[]]
- ? never // Reject string parameters in first position for FileId functions
- : T
- : T;
+ type SafeFileIdFunction<T extends (...args: never[]) => unknown> =
+ T extends (...args: infer P) => infer _R
+ ? P extends readonly [string, ...unknown[]]
+ ? never // Reject string parameters in first position for FileId functions
+ : T
+ : T;
// Mark functions that should only accept StirlingFile, not regular File
- type StirlingFileOnlyFunction<T extends (...args: any[]) => any> =
+ type StirlingFileOnlyFunction<T extends (...args: never[]) => unknown> =
T extends (...args: infer P) => infer _R
- ? P extends readonly [File, ...any[]]
+ ? P extends readonly [File, ...unknown[]]
? never // Reject File parameters in first position for StirlingFile functions
: T
: T;
diff --git a/frontend/editor/src/core/types/tool.ts b/frontend/editor/src/core/types/tool.ts
index 7a51d2c46a..3fbc6904e1 100644
--- a/frontend/editor/src/core/types/tool.ts
+++ b/frontend/editor/src/core/types/tool.ts
@@ -1,5 +1,4 @@
import React from "react";
-import { ToolOperationHook } from "@app/hooks/tools/shared/toolOperationTypes";
export type MaxFiles = number; // 1=single, >1=limited, -1=unlimited
export type ToolCategory =
@@ -27,13 +26,13 @@ export interface AutomationCapableTool {
* Static method that returns the operation hook for this tool.
* This enables automation to execute the tool programmatically.
*/
- tool: () => () => ToolOperationHook<any>;
+ tool: () => () => unknown;
/**
* Static method that returns the default parameters for this tool.
* This enables automation creation to initialize tools with proper defaults.
*/
- getDefaultParameters: () => any;
+ getDefaultParameters: () => unknown;
}
/**
@@ -61,7 +60,7 @@ export interface ToolResult {
files?: File[];
error?: string;
downloadUrl?: string;
- metadata?: Record<string, any>;
+ metadata?: Record<string, unknown>;
}
export interface ToolConfiguration {
diff --git a/frontend/editor/src/core/types/watchedFolders.ts b/frontend/editor/src/core/types/watchedFolders.ts
index ce8f7374e6..f87ce6e0a2 100644
--- a/frontend/editor/src/core/types/watchedFolders.ts
+++ b/frontend/editor/src/core/types/watchedFolders.ts
@@ -64,3 +64,10 @@ export interface WatchedFolderRunEntry {
processedAt?: Date;
status: "processing" | "processed";
}
+
+export interface WatchedFolderViewData {
+ /** Folder currently open in the view; null = the folder list / home. */
+ folderId: string | null;
+ pendingFileId?: string;
+ pendingFileIds?: string[];
+}
diff --git a/frontend/editor/src/core/utils/settingsPendingHelper.ts b/frontend/editor/src/core/utils/settingsPendingHelper.ts
index f15e3e1309..26c4ed2a5c 100644
--- a/frontend/editor/src/core/utils/settingsPendingHelper.ts
+++ b/frontend/editor/src/core/utils/settingsPendingHelper.ts
@@ -11,9 +11,9 @@
* }
*/
-export interface SettingsWithPending<T = any> {
+export interface SettingsWithPending<T = unknown> {
_pending?: Partial<T>;
- [key: string]: any;
+ [key: string]: unknown;
}
/**
@@ -97,7 +97,7 @@ export function hasPendingChanges<T extends SettingsWithPending>(
export function getPendingValue<T extends SettingsWithPending>(
settings: T | null | undefined,
fieldPath: string,
-): any {
+): unknown {
if (!settings?._pending) {
return undefined;
}
@@ -115,7 +115,7 @@ export function getPendingValue<T extends SettingsWithPending>(
export function getCurrentValue<T extends SettingsWithPending>(
settings: T | null | undefined,
fieldPath: string,
-): any {
+): unknown {
if (!settings) {
return undefined;
}
@@ -130,11 +130,11 @@ export function getCurrentValue<T extends SettingsWithPending>(
/**
* Deep merge two objects. Second object takes priority.
*/
-function deepMerge(target: any, source: any): any {
- if (!source) return target;
- if (!target) return source;
+function deepMerge(target: unknown, source: unknown): Record<string, unknown> {
+ const base = isPlainObject(target) ? target : {};
+ if (!isPlainObject(source)) return base;
- const result = { ...target };
+ const result: Record<string, unknown> = { ...base };
for (const key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
@@ -155,17 +155,17 @@ function deepMerge(target: any, source: any): any {
/**
* Get nested value using dot notation.
*/
-function getNestedValue(obj: any, path: string): any {
+function getNestedValue(obj: unknown, path: string): unknown {
if (!obj || !path) return undefined;
const parts = path.split(".");
- let current = obj;
+ let current: unknown = obj;
for (const part of parts) {
if (current === null || current === undefined) {
return undefined;
}
- current = current[part];
+ current = (current as Record<string, unknown>)[part];
}
return current;
@@ -174,8 +174,10 @@ function getNestedValue(obj: any, path: string): any {
/**
* Check if value is a plain object (not array, not null, not Date, etc.)
*/
-function isPlainObject(value: any): boolean {
+function isPlainObject(value: unknown): value is Record<string, unknown> {
return (
- value !== null && typeof value === "object" && value.constructor === Object
+ value !== null &&
+ typeof value === "object" &&
+ (value as { constructor?: unknown }).constructor === Object
);
}
diff --git a/frontend/editor/src/proprietary/components/watchedFolders/WatchedFolderWorkbenchView.tsx b/frontend/editor/src/proprietary/components/watchedFolders/WatchedFolderWorkbenchView.tsx
index f47d4fa64b..6330ebf481 100644
--- a/frontend/editor/src/proprietary/components/watchedFolders/WatchedFolderWorkbenchView.tsx
+++ b/frontend/editor/src/proprietary/components/watchedFolders/WatchedFolderWorkbenchView.tsx
@@ -57,6 +57,7 @@ import {
} from "@app/hooks/useFolderAutomation";
import { useLocalFolderPoller } from "@app/hooks/useLocalFolderPoller";
import { AutomationConfig } from "@app/types/automation";
+import type { WatchedFolderViewData } from "@app/types/watchedFolders";
import { iconMap } from "@app/components/tools/automate/iconMap";
import { fileStorage } from "@app/services/fileStorage";
import { FileId, StirlingFile } from "@app/types/fileContext";
@@ -166,11 +167,7 @@ function FilterSortBar({
}
interface WatchedFolderWorkbenchViewProps {
- data: {
- folderId: string | null;
- pendingFileId?: string;
- pendingFileIds?: string[];
- };
+ data: WatchedFolderViewData;
}
function RetryCountdown({
diff --git a/frontend/oxlint.config.ts b/frontend/oxlint.config.ts
index a52050bd7b..3921d87a95 100644
--- a/frontend/oxlint.config.ts
+++ b/frontend/oxlint.config.ts
@@ -74,7 +74,7 @@ const modernGlobals: OxlintGlobals = {
// Folders not yet conformant to the stricter no-explicit-any rule
const noExplicitAnyExcludes = [
- "editor/src/core/components/shared/config/configSections/*.{js,mjs,jsx,ts,tsx}",
+ "editor/src/core/components/shared/config/configSections/ProviderCard.tsx",
"editor/src/core/components/viewer/layerUtils.ts",
"editor/src/core/components/viewer/SignatureAPIBridge.tsx",
"editor/src/core/components/viewer/HistoryAPIBridge.tsx",
@@ -83,13 +83,9 @@ const noExplicitAnyExcludes = [
"editor/src/core/components/viewer/viewerTypes.ts",
"editor/src/core/components/viewer/EmbedPdfViewer.tsx",
"editor/src/core/components/viewer/RedactionSelectionMenu.tsx",
- "editor/src/core/contexts/ToolWorkflowContext.tsx",
"editor/src/core/tools/annotate/useAnnotationSelection.ts",
"editor/src/core/types/fileContext.ts",
- "editor/src/core/types/fileIdSafety.d.ts",
"editor/src/core/types/automation.ts",
- "editor/src/core/types/tool.ts",
- "editor/src/core/utils/settingsPendingHelper.ts",
];
export default defineConfig({