Skip to content

Commit

Permalink
@uppy/core: various type fixes (#4995)
Browse files Browse the repository at this point in the history
* @uppy/core: fix `addTarget` types

* @uppy/core: export `UploadResult` type

* @uppy/core: expose `clearUploadedFiles` for Dashboard

* @uppy/golden-retriever changes

---------

Co-authored-by: Murderlon <merlijn@soverin.net>
  • Loading branch information
aduh95 and Murderlon authored Mar 14, 2024
1 parent da623ff commit ac0f07a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/@uppy/core/src/BasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +111,7 @@ export default class BasePlugin<
*/

// eslint-disable-next-line @typescript-eslint/no-unused-vars
addTarget(plugin: unknown): HTMLElement {
addTarget(plugin: UnknownPlugin<M, B>): HTMLElement | null {
throw new Error(
"Extend the addTarget method to add your plugin to another plugin's target",
)
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class UIPlugin<

this.onMount()

return this.el
return this.el!
}

const targetPlugin = this.getTargetPlugin(target)
Expand All @@ -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}`)
Expand Down
13 changes: 8 additions & 5 deletions packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export type UnknownSearchProviderPlugin<
provider: CompanionClientSearchProvider
}

interface UploadResult<M extends Meta, B extends Body> {
export interface UploadResult<M extends Meta, B extends Body> {
successful?: UppyFile<M, B>[]
failed?: UppyFile<M, B>[]
uploadID?: string
Expand All @@ -156,10 +156,12 @@ export interface State<M extends Meta, B extends Body>
uploadProgress: boolean
individualCancellation: boolean
resumableUploads: boolean
isMobileDevice?: boolean
darkMode?: boolean
}
currentUploads: Record<string, CurrentUpload<M, B>>
allowNewUpload: boolean
recoveredState: null | State<M, B>
recoveredState: null | Required<Pick<State<M, B>, 'files' | 'currentUploads'>>
error: string | null
files: {
[key: string]: UppyFile<M, B>
Expand Down Expand Up @@ -317,8 +319,9 @@ export interface _UppyEventMap<M extends Meta, B extends Body> {
'preprocess-progress': PreProcessProgressCallback<M, B>
progress: ProgressCallback
'reset-progress': GenericEventCallback
restored: GenericEventCallback
restored: (pluginData: any) => void
'restore-confirmed': GenericEventCallback
'restore-canceled': GenericEventCallback
'restriction-failed': RestrictionFailedCallback<M, B>
'resume-all': GenericEventCallback
'retry-all': RetryAllCallback
Expand Down Expand Up @@ -635,7 +638,7 @@ export class Uppy<M extends Meta, B extends Body> {

// @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: {} })
}

Expand Down Expand Up @@ -1713,7 +1716,7 @@ export class Uppy<M extends Meta, B extends Body> {

#updateOnlineStatus = this.updateOnlineStatus.bind(this)

getID(): UppyOptions<M, B>['id'] {
getID(): string {
return this.opts.id
}

Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit ac0f07a

Please sign in to comment.