Skip to content

Commit 23bf229

Browse files
authored
@uppy/tus: correctly type tus on UppyFile (#5454)
* @uppy/tus: correctly type tus on UppyFile * Fix @uppy/transloadit
1 parent b936304 commit 23bf229

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

packages/@uppy/transloadit/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ErrorWithCause from '@uppy/utils/lib/ErrorWithCause'
33
import { RateLimitedQueue } from '@uppy/utils/lib/RateLimitedQueue'
44
import BasePlugin from '@uppy/core/lib/BasePlugin.js'
55
import type { DefinePluginOpts, PluginOpts } from '@uppy/core/lib/BasePlugin.js'
6-
import Tus, { type TusDetailedError } from '@uppy/tus'
6+
import Tus, { type TusDetailedError, type TusOpts } from '@uppy/tus'
77
import type { Body, Meta, UppyFile } from '@uppy/utils/lib/UppyFile'
88
import type { Uppy } from '@uppy/core'
99
import Assembly from './Assembly.ts'
@@ -219,7 +219,7 @@ declare module '@uppy/utils/lib/UppyFile' {
219219
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
220220
export interface UppyFile<M extends Meta, B extends Body> {
221221
transloadit?: { assembly: string }
222-
tus?: { uploadUrl?: string | null }
222+
tus?: TusOpts<M, B>
223223
}
224224
}
225225

@@ -936,7 +936,6 @@ export default class Transloadit<
936936
this.uppy.on('upload-success', this.#onFileUploadURLAvailable)
937937
} else {
938938
// we don't need it here.
939-
// @ts-expect-error `endpoint` is required but we first have to fetch
940939
// the regional endpoint from the Transloadit API before we can set it.
941940
this.uppy.use(Tus, {
942941
// Disable tus-js-client fingerprinting, otherwise uploading the same file at different times

packages/@uppy/tus/src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ import getFingerprint from './getFingerprint.ts'
2424
// @ts-ignore We don't want TS to generate types for the package.json
2525
import packageJson from '../package.json'
2626

27-
declare module '@uppy/utils/lib/UppyFile' {
28-
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
29-
export interface UppyFile<M extends Meta, B extends Body> {
30-
// TODO: figure out what else is in this type
31-
tus?: { uploadUrl?: string | null }
32-
}
33-
}
34-
3527
type RestTusUploadOptions = Omit<
3628
tus.UploadOptions,
3729
'onShouldRetry' | 'onBeforeRequest' | 'headers'
@@ -42,7 +34,7 @@ export type TusDetailedError = tus.DetailedError
4234
export interface TusOpts<M extends Meta, B extends Body>
4335
extends PluginOpts,
4436
RestTusUploadOptions {
45-
endpoint: string
37+
endpoint?: string
4638
headers?:
4739
| Record<string, string>
4840
| ((file: UppyFile<M, B>) => Record<string, string>)
@@ -102,6 +94,13 @@ type Opts<M extends Meta, B extends Body> = DefinePluginOpts<
10294
keyof typeof defaultOptions
10395
>
10496

97+
declare module '@uppy/utils/lib/UppyFile' {
98+
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
99+
export interface UppyFile<M extends Meta, B extends Body> {
100+
tus?: TusOpts<M, B>
101+
}
102+
}
103+
105104
/**
106105
* Tus resumable file uploader
107106
*/

0 commit comments

Comments
 (0)