Extend FileProgress type to support "already uploaded" files
Author: ninanatorCreated Sep 20, 2024Updated Aug 21, 2026
LabelsBug
Initial checklist
- I understand this is a bug report and questions should be posted in the Community Forum
- I searched issues and couldn’t find anything (or linked relevant results below)
Link to runnable example
No response
Steps to reproduce
The existing FileProgress type looks like:
// FileProgress is either started or not started. We want to make sure TS doesn't
// let us mix the two cases, and for that effect, we have one type for each case:
export type FileProgressStarted = FileProgressBase & {
uploadStarted: number
bytesUploaded: number
}
export type FileProgressNotStarted = FileProgressBase & {
uploadStarted: null
bytesUploaded: false
}
export type FileProgress = FileProgressStarted | FileProgressNotStartedHowever, the Uppy documentation still states (and still appears to support) setting files as already uploaded:
Expected behavior
The FileProgress type may need to look more like:
// FileProgress is either started, not started, or pre-uploaded. We want to make sure TS doesn't
// let us mix the two cases, and for that effect, we have one type for each case:
export type FileProgressStarted = FileProgressBase & {
uploadStarted: number
bytesUploaded: number
}
export type FileProgressNotStarted = FileProgressBase & {
uploadStarted: null
bytesUploaded: false
}
// Q: should the FileProgressBase be added here? I don't think any of those base values get set in this situation
export type FileProgressPreUploaded = {
uploadComplete: true
uploadStarted: true
}
export type FileProgress = FileProgressStarted | FileProgressNotStarted | FileProgressPreUploadedwhich would allow me to avoid writing a TypeScript exception and make it clear that this is supported behavior.
Actual behavior
Need to add a @ts-ignore or @ts-expect-error to allow (what appears to be) supported behavior
uppy.setFileState(fileId, {
progress: {
uploadComplete: true,
// @ts-expect-error Incorrectly typed, allow setting as true
uploadStarted: true,
},
});Source: transloadit/uppy