Skip to content

Commit

Permalink
@uppy/core: add PluginTarget type and mark options as optional (#4874)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Jan 19, 2024
1 parent 34ce4df commit d861fcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 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 @@ -43,9 +43,9 @@ export default class BasePlugin<

VERSION: string

constructor(uppy: Uppy<M, B>, opts: Opts) {
constructor(uppy: Uppy<M, B>, opts?: Partial<Opts>) {
this.uppy = uppy
this.opts = opts ?? {}
this.opts = (opts ?? {}) as Opts
}

getPluginState(): PluginState {
Expand Down
17 changes: 13 additions & 4 deletions packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class UIPlugin<

title: string

getTargetPlugin(target: unknown): UIPlugin<any, any, any> | undefined {
getTargetPlugin<Me extends Meta, Bo extends Body>(
target: PluginTarget<Me, Bo>, // eslint-disable-line no-use-before-define
): UIPlugin<any, Me, Bo> | undefined {
let targetPlugin
if (typeof target === 'object' && target instanceof UIPlugin) {
// Targeting a plugin *instance*
Expand All @@ -84,9 +86,9 @@ class UIPlugin<
* If it’s an object — target is a plugin, and we search `plugins`
* for a plugin with same name and return its target.
*/
mount(
target: HTMLElement | string,
plugin: UIPlugin<any, any, any>,
mount<Me extends Meta, Bo extends Body>(
target: PluginTarget<Me, Bo>, // eslint-disable-line no-use-before-define
plugin: UIPlugin<any, Me, Bo>,
): HTMLElement {
const callerPluginName = plugin.id

Expand Down Expand Up @@ -196,3 +198,10 @@ class UIPlugin<
}

export default UIPlugin

export type PluginTarget<M extends Meta, B extends Body> =
| string
| Element
| typeof BasePlugin
| typeof UIPlugin
| BasePlugin<any, M, B>

0 comments on commit d861fcd

Please sign in to comment.