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

Typings are incomplete #922

Closed
redevill opened this issue Jan 30, 2023 · 3 comments
Closed

Typings are incomplete #922

redevill opened this issue Jan 30, 2023 · 3 comments
Labels

Comments

@redevill
Copy link

  • Which support plan is this issue covered by? (Community):
  • Currently blocking your project/work? (no):
  • Affecting a production system? (yes):

Context

  • Node.js version: V16.15.0
  • Release Line of Formidable (Current):
  • Formidable exact version: V2.0.5
  • Environment (node, browser, native, OS): node
  • Used with (popular names of modules): express

What are you trying to achieve or the steps to reproduce?

Using a formidable form to upload images.
The upgraded version does not appear to match the given typings.

e.g. During run time a form.parse callback contains a File object, which in turn contains an image.
It appears that we need to cast from the specific "Image" back to file, as there is no Image object that implements the File interface.

Compile Error:
TS2339: Property originalFilename does not exist on type File | File[]   Property originalFilename does not exist on type File[]
const form = new formidable.IncomingForm(formOpts); form.parse(req, (err: Error, fields: Fields, file: Files) => { file.image.originalFilename }

What was the result you got?

Typescript Compile error

What result did you expect?

Better typings or guidance on expected usage.

@redevill redevill added the bug label Jan 30, 2023
@choutkamartin
Copy link

choutkamartin commented May 6, 2023

This is issue on your side:

Property originalFilename does not exist on type File[]

Property originalFilename can hardly exist on a type that is an array, not an object

The third argument of the callback function is either File or File[]. Not only File as you think.

@redevill
Copy link
Author

redevill commented May 8, 2023

So - if you are correct - and "This issue is on your side" and the only change I made was an upgrade in version, then it stands to reason, that the "issue" is the upgrade.

I am more accustomed to seeing "Breaking changes" listed in the change log.

For those that stumble here, (breaking change V1 to V2) there is some detail in the changelog:
Specifically #689
refactor: split file.name into file.newFilename and file.originalFilename (#689)

Additional checking to determine type when you get the call back is needed. per [choutkamartin] above.

@redevill redevill closed this as completed May 8, 2023
@JacobGalati
Copy link

@choutkamartin I ran into the same issue and realized that when I had installed formidable the @types/formidable package that came with it was v1. When I manually added @types/formidable as a dev dependency it came in with v2 and had the correct typings for Files.

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

3 participants