diff --git a/packages/@uppy/core/src/Uppy.test.ts b/packages/@uppy/core/src/Uppy.test.ts index 6f73e34452..f1b9971cfd 100644 --- a/packages/@uppy/core/src/Uppy.test.ts +++ b/packages/@uppy/core/src/Uppy.test.ts @@ -88,6 +88,7 @@ describe('src/Core', () => { this.bar = this.opts.bar } } + // @ts-expect-error missing mandatory option foo new Core().use(TestPlugin) new Core().use(TestPlugin, { foo: '', bar: '' }) // @ts-expect-error boolean not allowed diff --git a/packages/@uppy/core/src/Uppy.ts b/packages/@uppy/core/src/Uppy.ts index 7af5b7f815..fbde4e2d83 100644 --- a/packages/@uppy/core/src/Uppy.ts +++ b/packages/@uppy/core/src/Uppy.ts @@ -62,6 +62,9 @@ export type UnknownPlugin< PluginState extends Record = Record, > = BasePlugin +// `OmitFirstArg` is the type of the returned value of `someArray.slice(1)`. +type OmitFirstArg = T extends [any, ...infer U] ? U : never + export type UnknownProviderPluginState = { authenticated: boolean | undefined breadcrumbs: { @@ -1718,7 +1721,9 @@ export class Uppy { */ use>( Plugin: T, - opts?: ConstructorParameters[1], + // We want to let the plugin decide whether `opts` is optional or not + // so we spread the argument rather than defining `opts:` ourselves. + ...args: OmitFirstArg> ): this { if (typeof Plugin !== 'function') { const msg = @@ -1730,7 +1735,7 @@ export class Uppy { } // Instantiate - const plugin = new Plugin(this, opts) + const plugin = new Plugin(this, ...args) const pluginId = plugin.id if (!pluginId) { diff --git a/packages/@uppy/core/src/mocks/acquirerPlugin1.ts b/packages/@uppy/core/src/mocks/acquirerPlugin1.ts index 2968f37849..0f3516690d 100644 --- a/packages/@uppy/core/src/mocks/acquirerPlugin1.ts +++ b/packages/@uppy/core/src/mocks/acquirerPlugin1.ts @@ -9,7 +9,7 @@ export default class TestSelector1 extends UIPlugin { mocks: { run: mock; update: mock; uninstall: mock } - constructor(uppy: Uppy, opts: any) { + constructor(uppy: Uppy, opts?: any) { super(uppy, opts) this.type = 'acquirer' this.id = 'TestSelector1' diff --git a/packages/@uppy/core/src/mocks/acquirerPlugin2.ts b/packages/@uppy/core/src/mocks/acquirerPlugin2.ts index 01a5c2fa1c..9d2290b69d 100644 --- a/packages/@uppy/core/src/mocks/acquirerPlugin2.ts +++ b/packages/@uppy/core/src/mocks/acquirerPlugin2.ts @@ -9,7 +9,7 @@ export default class TestSelector2 extends UIPlugin { mocks: { run: mock; update: mock; uninstall: mock } - constructor(uppy: Uppy, opts: any) { + constructor(uppy: Uppy, opts?: any) { super(uppy, opts) this.type = 'acquirer' this.id = 'TestSelector2' diff --git a/packages/@uppy/core/src/mocks/invalidPluginWithoutId.ts b/packages/@uppy/core/src/mocks/invalidPluginWithoutId.ts index f24dc4b8f0..d2c02e30dc 100644 --- a/packages/@uppy/core/src/mocks/invalidPluginWithoutId.ts +++ b/packages/@uppy/core/src/mocks/invalidPluginWithoutId.ts @@ -6,7 +6,7 @@ export default class InvalidPluginWithoutName extends UIPlugin { public name: string - constructor(uppy: Uppy, opts: any) { + constructor(uppy: Uppy, opts?: any) { super(uppy, opts) this.type = 'acquirer' this.name = this.constructor.name diff --git a/packages/@uppy/core/src/mocks/invalidPluginWithoutType.ts b/packages/@uppy/core/src/mocks/invalidPluginWithoutType.ts index 3e600eaed4..4baeb573c9 100644 --- a/packages/@uppy/core/src/mocks/invalidPluginWithoutType.ts +++ b/packages/@uppy/core/src/mocks/invalidPluginWithoutType.ts @@ -6,7 +6,7 @@ export default class InvalidPluginWithoutType extends UIPlugin { public name: string - constructor(uppy: Uppy, opts: any) { + constructor(uppy: Uppy, opts?: any) { super(uppy, opts) this.id = 'InvalidPluginWithoutType' this.name = this.constructor.name