diff --git a/packages/@uppy/core/src/types.test.ts b/packages/@uppy/core/src/types.test.ts new file mode 100644 index 0000000000..e73cea2f4c --- /dev/null +++ b/packages/@uppy/core/src/types.test.ts @@ -0,0 +1,51 @@ +import { expectTypeOf, test } from 'vitest' + +import type { Body, InternalMetadata, Meta } from '@uppy/utils/lib/UppyFile' +import Uppy from './Uppy' +import UIPlugin, { type UIPluginOptions } from './UIPlugin' + +interface Opts extends UIPluginOptions { + foo: string +} +class TestPlugin extends UIPlugin { + constructor(uppy: Uppy, opts?: Opts) { + super(uppy, opts) + this.id = 'TestPlugin' + this.type = 'acquirer' + } +} + +test('can use Uppy class without generics', async () => { + const core = new Uppy() + expectTypeOf(core).toEqualTypeOf>() +}) + +test('can .use() a plugin', async () => { + const core = new Uppy().use(TestPlugin) + expectTypeOf(core).toEqualTypeOf>() +}) + +test('Meta and Body generic move through the Uppy class', async () => { + type M = { foo: string } + type B = { bar: string } + const core = new Uppy() + + core.addUploader(() => Promise.resolve()) + + core.on('complete', (result) => { + expectTypeOf(result.successful?.[0]?.response?.body).toEqualTypeOf< + B | undefined + >() + }) + + const id = core.addFile({ + source: 'vi', + name: 'foo.jpg', + type: 'image/jpeg', + data: new Blob(), + }) + + expectTypeOf(core.getFile(id).meta).toEqualTypeOf() + + await core.upload() +})