From ac0f07a7504f194e3cde74bd918160827cd98b06 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 14 Mar 2024 19:13:17 +0200 Subject: [PATCH] @uppy/core: various type fixes (#4995) * @uppy/core: fix `addTarget` types * @uppy/core: export `UploadResult` type * @uppy/core: expose `clearUploadedFiles` for Dashboard * @uppy/golden-retriever changes --------- Co-authored-by: Murderlon --- packages/@uppy/core/src/BasePlugin.ts | 4 ++-- packages/@uppy/core/src/UIPlugin.ts | 4 ++-- packages/@uppy/core/src/Uppy.ts | 13 ++++++++----- packages/@uppy/core/src/index.ts | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/@uppy/core/src/BasePlugin.ts b/packages/@uppy/core/src/BasePlugin.ts index b77de1e45..53bb06df8 100644 --- a/packages/@uppy/core/src/BasePlugin.ts +++ b/packages/@uppy/core/src/BasePlugin.ts @@ -16,7 +16,7 @@ import type { OptionalPluralizeLocale, } from '@uppy/utils/lib/Translator' import type { Body, Meta } from '@uppy/utils/lib/UppyFile' -import type { State, Uppy } from './Uppy' +import type { State, UnknownPlugin, Uppy } from './Uppy' export type PluginOpts = { locale?: Locale @@ -111,7 +111,7 @@ export default class BasePlugin< */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - addTarget(plugin: unknown): HTMLElement { + addTarget(plugin: UnknownPlugin): HTMLElement | null { throw new Error( "Extend the addTarget method to add your plugin to another plugin's target", ) diff --git a/packages/@uppy/core/src/UIPlugin.ts b/packages/@uppy/core/src/UIPlugin.ts index e44072151..e2d61291c 100644 --- a/packages/@uppy/core/src/UIPlugin.ts +++ b/packages/@uppy/core/src/UIPlugin.ts @@ -137,7 +137,7 @@ class UIPlugin< this.onMount() - return this.el + return this.el! } const targetPlugin = this.getTargetPlugin(target) @@ -148,7 +148,7 @@ class UIPlugin< this.el = targetPlugin.addTarget(plugin) this.onMount() - return this.el + return this.el! } this.uppy.log(`Not installing ${callerPluginName}`) diff --git a/packages/@uppy/core/src/Uppy.ts b/packages/@uppy/core/src/Uppy.ts index cea438653..ec338d581 100644 --- a/packages/@uppy/core/src/Uppy.ts +++ b/packages/@uppy/core/src/Uppy.ts @@ -132,7 +132,7 @@ export type UnknownSearchProviderPlugin< provider: CompanionClientSearchProvider } -interface UploadResult { +export interface UploadResult { successful?: UppyFile[] failed?: UppyFile[] uploadID?: string @@ -156,10 +156,12 @@ export interface State uploadProgress: boolean individualCancellation: boolean resumableUploads: boolean + isMobileDevice?: boolean + darkMode?: boolean } currentUploads: Record> allowNewUpload: boolean - recoveredState: null | State + recoveredState: null | Required, 'files' | 'currentUploads'>> error: string | null files: { [key: string]: UppyFile @@ -317,8 +319,9 @@ export interface _UppyEventMap { 'preprocess-progress': PreProcessProgressCallback progress: ProgressCallback 'reset-progress': GenericEventCallback - restored: GenericEventCallback + restored: (pluginData: any) => void 'restore-confirmed': GenericEventCallback + 'restore-canceled': GenericEventCallback 'restriction-failed': RestrictionFailedCallback 'resume-all': GenericEventCallback 'retry-all': RetryAllCallback @@ -635,7 +638,7 @@ export class Uppy { // @todo next major: rename to `clear()`, make it also cancel ongoing uploads // or throw and say you need to cancel manually - protected clearUploadedFiles(): void { + clearUploadedFiles(): void { this.setState({ ...defaultUploadState, files: {} }) } @@ -1713,7 +1716,7 @@ export class Uppy { #updateOnlineStatus = this.updateOnlineStatus.bind(this) - getID(): UppyOptions['id'] { + getID(): string { return this.opts.id } diff --git a/packages/@uppy/core/src/index.ts b/packages/@uppy/core/src/index.ts index ca8462d6c..6afec75f4 100644 --- a/packages/@uppy/core/src/index.ts +++ b/packages/@uppy/core/src/index.ts @@ -1,11 +1,12 @@ export { default } from './Uppy.ts' export { default as Uppy, - type UppyEventMap, type State, type UnknownPlugin, type UnknownProviderPlugin, type UnknownSearchProviderPlugin, + type UploadResult, + type UppyEventMap, } from './Uppy.ts' export { default as UIPlugin } from './UIPlugin.ts' export { default as BasePlugin } from './BasePlugin.ts'