diff --git a/packages/@uppy/core/types/index.d.ts b/packages/@uppy/core/types/index.d.ts index d34e43ab0d..afee94f1b9 100644 --- a/packages/@uppy/core/types/index.d.ts +++ b/packages/@uppy/core/types/index.d.ts @@ -21,7 +21,7 @@ export type FileProgress = UppyUtils.FileProgress; export type FileRemoveReason = 'removed-by-user' | 'cancel-all'; // Replace the `meta` property type with one that allows omitting internal metadata addFile() will add that -type UppyFileWithoutMeta = OmitKey< +type UppyFileWithoutMeta, TBody extends IndexedObject> = OmitKey< UppyFile, 'meta' > @@ -36,17 +36,23 @@ export type Store = UppyUtils.Store export type InternalMetadata = UppyUtils.InternalMetadata -export interface UploadedUppyFile extends UppyFile { +export interface UploadedUppyFile< + TMeta extends IndexedObject, + TBody extends IndexedObject + > extends UppyFile { uploadURL: string } -export interface FailedUppyFile extends UppyFile { +export interface FailedUppyFile< + TMeta extends IndexedObject, + TBody extends IndexedObject + > extends UppyFile { error: string } export interface AddFileOptions< - TMeta = IndexedObject, - TBody = IndexedObject + TMeta extends IndexedObject = IndexedObject, + TBody extends IndexedObject = IndexedObject > extends Partial> { // `.data` is the only required property here. data: Blob | File @@ -204,22 +210,27 @@ export interface SuccessResponse { } export type GenericEventCallback = () => void; -export type FileAddedCallback = (file: UppyFile) => void; -export type FilesAddedCallback = (files: UppyFile[]) => void; -export type FileRemovedCallback = (file: UppyFile, reason: FileRemoveReason) => void; +export type FileAddedCallback> = (file: UppyFile) => void; +export type FilesAddedCallback> = (files: UppyFile[]) => void; +export type FileRemovedCallback> = + (file: UppyFile, reason: FileRemoveReason) => void; export type UploadCallback = (data: { id: string, fileIDs: string[] }) => void; export type ProgressCallback = (progress: number) => void; -export type PreProcessCompleteCallback = (file: UppyFile | undefined) => void; -export type UploadProgressCallback = (file: UppyFile | undefined, progress: FileProgress) => void; -export type UploadSuccessCallback = (file: UppyFile | undefined, response: SuccessResponse) => void -export type UploadCompleteCallback = (result: UploadResult) => void +export type PreProcessCompleteCallback> = (file: UppyFile | undefined) => void; +export type UploadProgressCallback> = + (file: UppyFile | undefined, progress: FileProgress) => void; +export type UploadSuccessCallback> = + (file: UppyFile | undefined, response: SuccessResponse) => void +export type UploadCompleteCallback> = (result: UploadResult) => void export type ErrorCallback = (error: Error) => void; -export type UploadErrorCallback = (file: UppyFile | undefined, error: Error, response?: ErrorResponse) => void; +export type UploadErrorCallback> = + (file: UppyFile | undefined, error: Error, response?: ErrorResponse) => void; export type UploadRetryCallback = (fileID: string) => void; export type RetryAllCallback = (fileIDs: string[]) => void; -export type RestrictionFailedCallback = (file: UppyFile | undefined, error: Error) => void; +export type RestrictionFailedCallback> = + (file: UppyFile | undefined, error: Error) => void; -export interface UppyEventMap> { +export interface UppyEventMap = Record> { 'file-added': FileAddedCallback 'files-added': FilesAddedCallback 'file-removed': FileRemovedCallback @@ -349,7 +360,7 @@ export class Uppy { getID(): string - use>( + use( pluginClass: new (uppy: this, opts: TOptions) => TInstance, opts?: TOptions ): this diff --git a/packages/@uppy/dashboard/types/index.d.ts b/packages/@uppy/dashboard/types/index.d.ts index d168504490..e8097a0115 100644 --- a/packages/@uppy/dashboard/types/index.d.ts +++ b/packages/@uppy/dashboard/types/index.d.ts @@ -1,4 +1,4 @@ -import type { PluginOptions, UIPlugin, PluginTarget, UppyFile, GenericEventCallback } from '@uppy/core' +import type { PluginOptions, UIPlugin, PluginTarget, UppyFile, IndexedObject } from '@uppy/core' import type { StatusBarLocale } from '@uppy/status-bar' import type { ThumbnailOptions } from '@uppy/thumbnail-generator' import DashboardLocale from './generatedLocale' @@ -86,8 +86,8 @@ export default Dashboard // Events -export type DashboardFileEditStartCallback = (file?: UppyFile) => void; -export type DashboardFileEditCompleteCallback = (file?: UppyFile) => void; +export type DashboardFileEditStartCallback> = (file?: UppyFile) => void; +export type DashboardFileEditCompleteCallback> = (file?: UppyFile) => void; declare module '@uppy/core' { export interface UppyEventMap { 'dashboard:modal-open': GenericEventCallback diff --git a/packages/@uppy/thumbnail-generator/types/index.d.ts b/packages/@uppy/thumbnail-generator/types/index.d.ts index 113b4c9d7d..e86a7d2479 100644 --- a/packages/@uppy/thumbnail-generator/types/index.d.ts +++ b/packages/@uppy/thumbnail-generator/types/index.d.ts @@ -1,4 +1,4 @@ -import type { PluginOptions, UIPlugin, UppyFile } from '@uppy/core' +import type { IndexedObject, PluginOptions, UIPlugin, UppyFile } from '@uppy/core' import ThumbnailGeneratorLocale from './generatedLocale' @@ -20,7 +20,7 @@ export default ThumbnailGenerator // Events -export type ThumbnailGeneratedCallback = ( +export type ThumbnailGeneratedCallback> = ( file: UppyFile, preview: string ) => void