From 9d30f341d367481662647d518b017a48e8d53dc0 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 3 Aug 2026 16:32:42 +0200 Subject: [PATCH 1/5] Fix all $TSFixMe instances There are some slight logic changes because of issues revealed by the new type errors that surfaced. Also some type errors have now been suppressed and need a closer look later. --- packages/@uppy/core/src/UIPlugin.ts | 2 +- packages/@uppy/dashboard/src/Dashboard.tsx | 11 ++-- .../dashboard/src/components/AddFiles.tsx | 2 +- .../src/components/AddFilesPanel.tsx | 11 +++- .../dashboard/src/components/Dashboard.tsx | 12 ++-- .../dashboard/src/components/EditorPanel.tsx | 47 ++++++++++++++-- .../components/FileCard/RenderMetaFields.tsx | 19 +++++-- .../src/components/FileCard/index.tsx | 39 ++++++++++--- .../src/components/FileItem/Buttons/index.tsx | 9 ++- .../FileItem/FilePreviewAndLink/index.tsx | 14 ++++- .../components/FileItem/MetaErrorMessage.tsx | 35 +++++++++--- .../dashboard/src/components/FilePreview.tsx | 10 +++- .../src/components/PickerPanelContent.tsx | 23 ++++++-- .../src/components/PickerPanelTopBar.tsx | 55 ++++++++++++++----- packages/@uppy/dashboard/src/index.test.ts | 5 +- .../dashboard/src/utils/copyToClipboard.ts | 35 +++++------- .../dashboard/src/utils/createSuperFocus.ts | 34 +++++++----- .../dashboard/src/utils/getActiveOverlayEl.ts | 12 ++-- .../dashboard/src/utils/getFileTypeIcon.tsx | 9 ++- .../@uppy/dashboard/src/utils/ignoreEvent.ts | 6 +- .../@uppy/dashboard/src/utils/trapFocus.ts | 26 ++++----- .../@uppy/screen-capture/src/StopWatch.tsx | 24 +++++--- .../@uppy/screen-capture/src/StreamStatus.tsx | 13 ++++- 23 files changed, 311 insertions(+), 142 deletions(-) diff --git a/packages/@uppy/core/src/UIPlugin.ts b/packages/@uppy/core/src/UIPlugin.ts index 774d0b4b44..eb9cde9763 100644 --- a/packages/@uppy/core/src/UIPlugin.ts +++ b/packages/@uppy/core/src/UIPlugin.ts @@ -45,7 +45,7 @@ class UIPlugin< isTargetDOMEl!: boolean - el!: HTMLElement | null + el: HTMLElement | null = null parent: unknown diff --git a/packages/@uppy/dashboard/src/Dashboard.tsx b/packages/@uppy/dashboard/src/Dashboard.tsx index a2a674b331..efcbe3589c 100644 --- a/packages/@uppy/dashboard/src/Dashboard.tsx +++ b/packages/@uppy/dashboard/src/Dashboard.tsx @@ -78,11 +78,12 @@ type PreactRender = ( ...children: any[] ) => VNode -interface MetaField { +export interface MetaField { id: string name: string placeholder?: string render?: (field: FieldRenderOptions, h: PreactRender) => VNode + type?: string } interface Target { @@ -98,7 +99,7 @@ export interface TargetWithRender extends Target { export interface DashboardState { targets: Target[] - activePickerPanel: Target | undefined + activePickerPanel: Target showAddFilesPanel: boolean activeOverlayType: string | null fileCardFor: string | null @@ -747,7 +748,7 @@ export default class Dashboard extends UIPlugin< trapFocus.forModal( event, this.getPluginState().activeOverlayType, - this.el, + this.el!, ) } @@ -902,7 +903,7 @@ export default class Dashboard extends UIPlugin< trapFocus.forInline( event, this.getPluginState().activeOverlayType, - this.el, + this.el!, ) } @@ -1076,7 +1077,7 @@ export default class Dashboard extends UIPlugin< // try to press space multiple times. Focus will jump to Uppy. (isFocusNowhere && this.ifFocusedOnUppyRecently)) ) { - this.superFocus(this.el, this.getPluginState().activeOverlayType) + this.superFocus(this.el!, this.getPluginState().activeOverlayType) } else { this.superFocus.cancel() } diff --git a/packages/@uppy/dashboard/src/components/AddFiles.tsx b/packages/@uppy/dashboard/src/components/AddFiles.tsx index 267f40016a..c72df20030 100644 --- a/packages/@uppy/dashboard/src/components/AddFiles.tsx +++ b/packages/@uppy/dashboard/src/components/AddFiles.tsx @@ -7,7 +7,7 @@ import { } from '@uppy/core/utils/preact' import type { DashboardState, TargetWithRender } from '../Dashboard.js' -interface AddFilesProps { +export interface AddFilesProps { i18n: I18n i18nArray: Translator['translateArray'] acquirers: TargetWithRender[] diff --git a/packages/@uppy/dashboard/src/components/AddFilesPanel.tsx b/packages/@uppy/dashboard/src/components/AddFilesPanel.tsx index 40964abe90..56581c6432 100644 --- a/packages/@uppy/dashboard/src/components/AddFilesPanel.tsx +++ b/packages/@uppy/dashboard/src/components/AddFilesPanel.tsx @@ -1,9 +1,15 @@ import classNames from 'classnames' +import type { ComponentChildren } from 'preact' +import type { AddFilesProps } from './AddFiles.js' import AddFiles from './AddFiles.js' -type $TSFixMe = any +interface AddFilesPanelProps extends AddFilesProps { + className?: string | undefined + showAddFilesPanel: boolean + toggleAddFilesPanel: (enabled: boolean) => void +} -const AddFilesPanel = (props: $TSFixMe): $TSFixMe => { +const AddFilesPanel = (props: AddFilesPanelProps): ComponentChildren => { return (
{ {props.i18n('back')}
- {} ) diff --git a/packages/@uppy/dashboard/src/components/Dashboard.tsx b/packages/@uppy/dashboard/src/components/Dashboard.tsx index 4f5072dc92..091ab29969 100644 --- a/packages/@uppy/dashboard/src/components/Dashboard.tsx +++ b/packages/@uppy/dashboard/src/components/Dashboard.tsx @@ -57,7 +57,7 @@ type DashboardUIProps = { disabled: boolean disableLocalFiles: boolean direction: UIPluginOptions['direction'] - activePickerPanel: DashboardState['activePickerPanel'] + activePickerPanel: NonNullable['activePickerPanel']> showFileEditor: boolean saveFileEditor: () => void closeFileEditor: () => void @@ -108,7 +108,7 @@ type DashboardUIProps = { parentElement: HTMLElement | null allowedFileTypes: string[] | null maxNumberOfFiles: number | null - requiredMetaFields: any + requiredMetaFields: string[] showSelectedFiles: boolean showNativePhotoCameraButton: boolean showNativeVideoCameraButton: boolean @@ -131,9 +131,9 @@ type DashboardUIProps = { export default function Dashboard( props: DashboardUIProps, ) { + const { fileCardFor } = props const isNoFiles = props.totalFileCount === 0 const isSingleFile = props.totalFileCount === 1 - const isSizeMD = props.containerWidth > WIDTH_MD const isSizeHeightMD = props.containerHeight > HEIGHT_MD const dashboardClassName = classNames({ @@ -320,12 +320,14 @@ export default function Dashboard( {props.showAddFilesPanel ? ( - + ) : null} - {props.fileCardFor ? : null} + {fileCardFor ? ( + + ) : null} diff --git a/packages/@uppy/dashboard/src/components/EditorPanel.tsx b/packages/@uppy/dashboard/src/components/EditorPanel.tsx index e6771b9e3d..0e543c3ca7 100644 --- a/packages/@uppy/dashboard/src/components/EditorPanel.tsx +++ b/packages/@uppy/dashboard/src/components/EditorPanel.tsx @@ -1,9 +1,39 @@ +import type Uppy from '@uppy/core' +import type { Body, State, UIPlugin } from '@uppy/core' +import type { + I18n, + Meta, + Translator, + UppyFile, + UppyFileId, +} from '@uppy/core/utils' import classNames from 'classnames' +import type { ComponentChildren, MouseEventHandler } from 'preact' +import type { TargetWithRender } from '../Dashboard.js' -type $TSFixMe = any +declare module '@uppy/core' { + export interface UppyEventMap { + 'file-editor:cancel': (file: UppyFile) => void + } +} + +type EditorPanelProps = { + className?: string | undefined + closeFileEditor: () => void + editors: TargetWithRender[] + fileCardFor: UppyFileId | null + files: State['files'] + i18n: I18n + i18nArray: Translator['translateArray'] + saveFileEditor: MouseEventHandler + state: State + uppy: Uppy +} -function EditorPanel(props: $TSFixMe) { - const file = props.files[props.fileCardFor] +function EditorPanel( + props: EditorPanelProps, +): ComponentChildren { + const file = props.files[props.fileCardFor!] const handleCancel = () => { props.uppy.emit('file-editor:cancel', file) @@ -47,8 +77,15 @@ function EditorPanel(props: $TSFixMe) {
- {props.editors.map((target: $TSFixMe) => { - return props.uppy.getPlugin(target.id).render(props.state) + {props.editors.map((target) => { + return ( + props.uppy.getPlugin(target.id) as UIPlugin< + // biome-ignore lint/complexity/noBannedTypes: {} means anything except null or undefined. + {}, + M, + B + > + ).render(props.state) })}
diff --git a/packages/@uppy/dashboard/src/components/FileCard/RenderMetaFields.tsx b/packages/@uppy/dashboard/src/components/FileCard/RenderMetaFields.tsx index cff940a22d..845f63ae7e 100644 --- a/packages/@uppy/dashboard/src/components/FileCard/RenderMetaFields.tsx +++ b/packages/@uppy/dashboard/src/components/FileCard/RenderMetaFields.tsx @@ -1,8 +1,17 @@ -import { h } from '@uppy/core/utils/preact' +import { type ComponentChildren, h } from '@uppy/core/utils/preact' +import type { MetaField } from '../../Dashboard.js' -type $TSFixMe = any +interface RenderMetaFieldsProps { + computedMetaFields: MetaField[] + requiredMetaFields: string[] + updateMeta: (newVal: string, fieldId: string) => void + form: HTMLFormElement + formState: Record +} -export default function RenderMetaFields(props: $TSFixMe) { +export default function RenderMetaFields( + props: RenderMetaFieldsProps, +): ComponentChildren { const { computedMetaFields, requiredMetaFields, @@ -15,7 +24,7 @@ export default function RenderMetaFields(props: $TSFixMe) { text: 'uppy-u-reset uppy-c-textInput uppy-Dashboard-FileCard-input', } - return computedMetaFields.map((field: $TSFixMe) => { + return computedMetaFields.map((field) => { const id = `uppy-Dashboard-FileCard-input-${field.id}` const required = requiredMetaFields.includes(field.id) return ( @@ -27,7 +36,7 @@ export default function RenderMetaFields(props: $TSFixMe) { field.render( { value: formState[field.id], - onChange: (newVal: $TSFixMe) => updateMeta(newVal, field.id), + onChange: (newVal) => updateMeta(newVal, field.id), fieldCSSClasses, required, form: form.id, diff --git a/packages/@uppy/dashboard/src/components/FileCard/index.tsx b/packages/@uppy/dashboard/src/components/FileCard/index.tsx index dad0b3fb07..12cfe2156d 100644 --- a/packages/@uppy/dashboard/src/components/FileCard/index.tsx +++ b/packages/@uppy/dashboard/src/components/FileCard/index.tsx @@ -1,3 +1,5 @@ +import type { Body, Meta, State } from '@uppy/core' +import type { I18n, Translator, UppyFile } from '@uppy/core/utils' import { useCallback, useEffect, @@ -6,14 +8,30 @@ import { } from '@uppy/core/utils/preact/hooks' import classNames from 'classnames' import { nanoid } from 'nanoid/non-secure' +import type { ComponentChildren, TargetedMouseEvent } from 'preact' +import type { DashboardState } from '../../Dashboard.js' import getFileTypeIcon from '../../utils/getFileTypeIcon.js' import ignoreEvent from '../../utils/ignoreEvent.js' import FilePreview from '../FilePreview.js' import RenderMetaFields from './RenderMetaFields.js' -type $TSFixMe = any +interface FileCardProps { + canEditFile: (file: UppyFile) => boolean + className?: string | undefined + fileCardFor: string + files: State['files'] + i18n: I18n + i18nArray: Translator['translateArray'] + metaFields: DashboardState['metaFields'] + openFileEditor: (file: UppyFile) => void + requiredMetaFields: string[] + saveFileCard: (meta: M, fileID: string) => void + toggleFileCard: (show: boolean, fileID: string) => void +} -export default function FileCard(props: $TSFixMe) { +export default function FileCard( + props: FileCardProps, +): ComponentChildren { const { files, fileCardFor, @@ -30,30 +48,31 @@ export default function FileCard(props: $TSFixMe) { const getMetaFields = () => { return typeof metaFields === 'function' - ? metaFields(files[fileCardFor]) + ? metaFields(files[fileCardFor!]) : metaFields } - const file = files[fileCardFor] + const file = files[fileCardFor!] const computedMetaFields = getMetaFields() ?? [] const showEditButton = canEditFile(file) - const storedMetaData: Record = {} - computedMetaFields.forEach((field: $TSFixMe) => { + const storedMetaData = {} as M + computedMetaFields.forEach((field) => { + // @ts-expect-error TODO fix me storedMetaData[field.id] = file.meta[field.id] ?? '' }) const [formState, setFormState] = useState(storedMetaData) const handleSave = useCallback( - (ev: $TSFixMe) => { + (ev: SubmitEvent | TargetedMouseEvent) => { ev.preventDefault() saveFileCard(formState, fileCardFor) }, [saveFileCard, formState, fileCardFor], ) - const updateMeta = (newVal: $TSFixMe, name: $TSFixMe) => { + const updateMeta = (newVal: string, name: string) => { setFormState({ ...formState, [name]: newVal, @@ -61,6 +80,7 @@ export default function FileCard(props: $TSFixMe) { } const handleCancel = () => { + // @ts-expect-error TODO fix me toggleFileCard(false) } @@ -152,7 +172,7 @@ export default function FileCard(props: $TSFixMe) {