diff --git a/packages/@uppy/core/src/Uppy.test.ts b/packages/@uppy/core/src/Uppy.test.ts index e279dbdd3c..c4ee610427 100644 --- a/packages/@uppy/core/src/Uppy.test.ts +++ b/packages/@uppy/core/src/Uppy.test.ts @@ -7,8 +7,10 @@ import assert from 'node:assert' import fs from 'node:fs' import path from 'node:path' import prettierBytes from '@transloadit/prettier-bytes' +import type { Body, Meta } from '@uppy/utils/lib/UppyFile' import Core from './index.ts' import UIPlugin from './UIPlugin.ts' +import BasePlugin, { type PluginOpts } from './BasePlugin.ts' import { debugLogger } from './loggers.ts' import AcquirerPlugin1 from './mocks/acquirerPlugin1.ts' import AcquirerPlugin2 from './mocks/acquirerPlugin2.ts' @@ -61,6 +63,33 @@ describe('src/Core', () => { ).toEqual(1) }) + it('should be able to .use() without passing generics again', () => { + interface TestOpts extends PluginOpts { + foo?: string + bar: string + } + class TestPlugin extends BasePlugin< + TestOpts, + M, + B + > { + foo: string + + constructor(uppy: Core, opts: TestOpts) { + super(uppy, opts) + this.id = 'Test' + this.type = 'acquirer' + this.foo = opts?.foo ?? 'bar' + } + } + new Core().use(TestPlugin) + new Core().use(TestPlugin, { foo: '', bar: '' }) + // @ts-expect-error boolean not allowed + new Core().use(TestPlugin, { foo: false }) + // @ts-expect-error missing option + new Core().use(TestPlugin, { foo: '' }) + }) + it('should prevent the same plugin from being added more than once', () => { const core = new Core() core.use(AcquirerPlugin1) diff --git a/packages/@uppy/core/src/Uppy.ts b/packages/@uppy/core/src/Uppy.ts index 8ab01aa003..368416f016 100644 --- a/packages/@uppy/core/src/Uppy.ts +++ b/packages/@uppy/core/src/Uppy.ts @@ -39,7 +39,6 @@ import locale from './locale.ts' import type BasePlugin from './BasePlugin.ts' import type UIPlugin from './UIPlugin.ts' import type { Restrictions } from './Restricter.ts' -import type { PluginOpts } from './BasePlugin.ts' type Processor = (fileIDs: string[], uploadID: string) => Promise | void @@ -1663,9 +1662,9 @@ export class Uppy { /** * Registers a plugin with Core. */ - use | BasePlugin>( - Plugin: new (uppy: this, opts?: O) => I, - opts?: O, + use | typeof UIPlugin>( + Plugin: T, + opts?: ConstructorParameters[1], ): this { if (typeof Plugin !== 'function') { const msg =