Skip to content

Commit

Permalink
@uppy/core,@uppy/dashboard: fix types for some events (#3812)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 7, 2022
1 parent 91e08c1 commit b7ecab5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/@uppy/core/types/index.d.ts
Expand Up @@ -209,12 +209,12 @@ export type FilesAddedCallback<TMeta> = (files: UppyFile<TMeta>[]) => void;
export type FileRemovedCallback<TMeta> = (file: UppyFile<TMeta>, reason: FileRemoveReason) => void;
export type UploadCallback = (data: { id: string, fileIDs: string[] }) => void;
export type ProgressCallback = (progress: number) => void;
export type PreProcessCompleteCallback<TMeta> = (file: UppyFile<TMeta>) => void;
export type UploadProgressCallback<TMeta> = (file: UppyFile<TMeta>, progress: FileProgress) => void;
export type UploadSuccessCallback<TMeta> = (file: UppyFile<TMeta>, response: SuccessResponse) => void
export type PreProcessCompleteCallback<TMeta> = (file: UppyFile<TMeta> | undefined) => void;
export type UploadProgressCallback<TMeta> = (file: UppyFile<TMeta> | undefined, progress: FileProgress) => void;
export type UploadSuccessCallback<TMeta> = (file: UppyFile<TMeta> | undefined, response: SuccessResponse) => void
export type UploadCompleteCallback<TMeta> = (result: UploadResult<TMeta>) => void
export type ErrorCallback = (error: Error) => void;
export type UploadErrorCallback<TMeta> = (file: UppyFile<TMeta>, error: Error, response?: ErrorResponse) => void;
export type UploadErrorCallback<TMeta> = (file: UppyFile<TMeta> | undefined, error: Error, response?: ErrorResponse) => void;
export type UploadRetryCallback = (fileID: string) => void;
// TODO: reverse the order in the next major version
export type RestrictionFailedCallback<TMeta> = (file: UppyFile<TMeta> | undefined, error: Error) => void;
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/core/types/index.test-d.ts
Expand Up @@ -104,8 +104,8 @@ type anyObject = Record<string, unknown>
})

// Separate event handlers
const handleUpload = (file: UppyFile<Meta>) => {
const meta = file.meta.myCustomMetadata
const handleUpload = (file?: UppyFile<Meta>) => {
const meta = file?.meta.myCustomMetadata
}

uppy.off<'upload-success', Meta>('upload-success', handleUpload)
Expand All @@ -114,7 +114,7 @@ type anyObject = Record<string, unknown>
body?: { someValue: string }
}

const onUploadSuccess = async (file: UppyFile<Meta, any>, response: CustomResponse) => {
const onUploadSuccess = async (file: UppyFile<Meta, any> | undefined, response: CustomResponse) => {
const res = response.body?.someValue
}
uppy.on<'upload-success', Meta>('upload-success', onUploadSuccess)
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/dashboard/types/index.d.ts
Expand Up @@ -84,8 +84,8 @@ export default Dashboard

// Events

export type DashboardFileEditStartCallback<TMeta> = (file: UppyFile<TMeta>) => void;
export type DashboardFileEditCompleteCallback<TMeta> = (file: UppyFile<TMeta>) => void;
export type DashboardFileEditStartCallback<TMeta> = (file?: UppyFile<TMeta>) => void;
export type DashboardFileEditCompleteCallback<TMeta> = (file?: UppyFile<TMeta>) => void;
declare module '@uppy/core' {
export interface UppyEventMap<TMeta> {
'dashboard:modal-open': GenericEventCallback
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/dashboard/types/index.test-d.ts
Expand Up @@ -54,7 +54,7 @@ import Dashboard from '..'

uppy.on('dashboard:file-edit-state', (file) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const fileName = file.name
const fileName = file?.name
})
}

Expand Down

0 comments on commit b7ecab5

Please sign in to comment.