Skip to content

Commit

Permalink
@uppy/tus: correctly type tus on UppyFile (#5454)
Browse files Browse the repository at this point in the history
* @uppy/tus: correctly type tus on UppyFile

* Fix @uppy/transloadit
  • Loading branch information
Murderlon authored Sep 9, 2024
1 parent b936304 commit 23bf229
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions packages/@uppy/transloadit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ErrorWithCause from '@uppy/utils/lib/ErrorWithCause'
import { RateLimitedQueue } from '@uppy/utils/lib/RateLimitedQueue'
import BasePlugin from '@uppy/core/lib/BasePlugin.js'
import type { DefinePluginOpts, PluginOpts } from '@uppy/core/lib/BasePlugin.js'
import Tus, { type TusDetailedError } from '@uppy/tus'
import Tus, { type TusDetailedError, type TusOpts } from '@uppy/tus'
import type { Body, Meta, UppyFile } from '@uppy/utils/lib/UppyFile'
import type { Uppy } from '@uppy/core'
import Assembly from './Assembly.ts'
Expand Down Expand Up @@ -219,7 +219,7 @@ declare module '@uppy/utils/lib/UppyFile' {
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
export interface UppyFile<M extends Meta, B extends Body> {
transloadit?: { assembly: string }
tus?: { uploadUrl?: string | null }
tus?: TusOpts<M, B>
}
}

Expand Down Expand Up @@ -936,7 +936,6 @@ export default class Transloadit<
this.uppy.on('upload-success', this.#onFileUploadURLAvailable)
} else {
// we don't need it here.
// @ts-expect-error `endpoint` is required but we first have to fetch
// the regional endpoint from the Transloadit API before we can set it.
this.uppy.use(Tus, {
// Disable tus-js-client fingerprinting, otherwise uploading the same file at different times
Expand Down
17 changes: 8 additions & 9 deletions packages/@uppy/tus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ import getFingerprint from './getFingerprint.ts'
// @ts-ignore We don't want TS to generate types for the package.json
import packageJson from '../package.json'

declare module '@uppy/utils/lib/UppyFile' {
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
export interface UppyFile<M extends Meta, B extends Body> {
// TODO: figure out what else is in this type
tus?: { uploadUrl?: string | null }
}
}

type RestTusUploadOptions = Omit<
tus.UploadOptions,
'onShouldRetry' | 'onBeforeRequest' | 'headers'
Expand All @@ -42,7 +34,7 @@ export type TusDetailedError = tus.DetailedError
export interface TusOpts<M extends Meta, B extends Body>
extends PluginOpts,
RestTusUploadOptions {
endpoint: string
endpoint?: string
headers?:
| Record<string, string>
| ((file: UppyFile<M, B>) => Record<string, string>)
Expand Down Expand Up @@ -102,6 +94,13 @@ type Opts<M extends Meta, B extends Body> = DefinePluginOpts<
keyof typeof defaultOptions
>

declare module '@uppy/utils/lib/UppyFile' {
// eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars
export interface UppyFile<M extends Meta, B extends Body> {
tus?: TusOpts<M, B>
}
}

/**
* Tus resumable file uploader
*/
Expand Down

0 comments on commit 23bf229

Please sign in to comment.