Skip to content

Commit

Permalink
Correct type definition for onSuccess callback
Browse files Browse the repository at this point in the history
Fixes #716
  • Loading branch information
Acconut committed Sep 10, 2024
1 parent 3479244 commit 05b5feb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface UploadOptions {

onProgress?: ((bytesSent: number, bytesTotal: number) => void) | null
onChunkComplete?: ((chunkSize: number, bytesAccepted: number, bytesTotal: number) => void) | null
onSuccess?: (() => void) | null
onSuccess?: ((payload: OnSuccessPayload) => void) | null
onError?: ((error: Error | DetailedError) => void) | null
onShouldRetry?:
| ((error: DetailedError, retryAttempt: number, options: UploadOptions) => boolean)
Expand All @@ -59,6 +59,10 @@ interface UploadOptions {
httpStack?: HttpStack
}

interface OnSuccessPayload {
lastResponse: HttpResponse
}

interface UrlStorage {
findAllUploads(): Promise<PreviousUpload[]>
findUploadsByFingerprint(fingerprint: string): Promise<PreviousUpload[]>
Expand Down
3 changes: 2 additions & 1 deletion lib/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const upload = new tus.Upload(file, {
console.log(bytesSent, bytesTotal, `${percentage}%`)
},
onChunkComplete: (_chunkSize: number, _bytesAccepted: number) => {},
onSuccess: () => {
onSuccess: (payload: tus.OnSuccessPayload) => {
console.log('Download from %s complete', upload.url)
console.log('Response header', payload.lastResponse.getHeader('X-Info'))
},
onError: (error: Error | DetailedError) => {
console.error(`Failed because: ${error}`)
Expand Down

0 comments on commit 05b5feb

Please sign in to comment.