Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend FileProgress type to support "already uploaded" files #5468

Open
2 tasks done
ninanator opened this issue Sep 20, 2024 · 0 comments
Open
2 tasks done

Extend FileProgress type to support "already uploaded" files #5468

ninanator opened this issue Sep 20, 2024 · 0 comments
Labels

Comments

@ninanator
Copy link

ninanator commented Sep 20, 2024

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 | FileProgressNotStarted

However, the Uppy documentation still states (and still appears to support) setting files as already uploaded:

uppy-documentation

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 | FileProgressPreUploaded

which 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,
  },
});
@ninanator ninanator added the Bug label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant