From 41483c19c2f7d4c52a77596c03ca0c3ab74fbea3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 18 Jan 2024 16:24:42 +0100 Subject: [PATCH] @uppy/core: add `PluginTarget` type --- packages/@uppy/core/src/BasePlugin.ts | 4 ++-- packages/@uppy/core/src/UIPlugin.ts | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/@uppy/core/src/BasePlugin.ts b/packages/@uppy/core/src/BasePlugin.ts index 787c6b45b8..64244e5851 100644 --- a/packages/@uppy/core/src/BasePlugin.ts +++ b/packages/@uppy/core/src/BasePlugin.ts @@ -43,9 +43,9 @@ export default class BasePlugin< VERSION: string - constructor(uppy: Uppy, opts: Opts) { + constructor(uppy: Uppy, opts?: Partial) { this.uppy = uppy - this.opts = opts ?? {} + this.opts = (opts ?? {}) as Opts } getPluginState(): PluginState { diff --git a/packages/@uppy/core/src/UIPlugin.ts b/packages/@uppy/core/src/UIPlugin.ts index 47f725da61..36099ee2f9 100644 --- a/packages/@uppy/core/src/UIPlugin.ts +++ b/packages/@uppy/core/src/UIPlugin.ts @@ -60,7 +60,9 @@ class UIPlugin< title: string - getTargetPlugin(target: unknown): UIPlugin | undefined { + getTargetPlugin( + target: PluginTarget, // eslint-disable-line no-use-before-define + ): UIPlugin | undefined { let targetPlugin if (typeof target === 'object' && target instanceof UIPlugin) { // Targeting a plugin *instance* @@ -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, + mount( + target: PluginTarget, // eslint-disable-line no-use-before-define + plugin: UIPlugin, ): HTMLElement { const callerPluginName = plugin.id @@ -196,3 +198,10 @@ class UIPlugin< } export default UIPlugin + +export type PluginTarget = + | string + | Element + | typeof BasePlugin + | typeof UIPlugin + | BasePlugin