node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7k stars 680 forks source link

Type looks wrong? #802

Closed pierznj closed 2 years ago

pierznj commented 2 years ago

Here's the TS definition for the fileWriteStreamHandler option. Note that the return type is void but the comments (and code examples concur) say to return a writeable stream. Am I missing something? Currently I can't use it, unless I cast the type of the function but before I do that I want to know if I'm misunderstanding.

 /**
         * which by default writes to host machine file system every file parsed; The function should
         * return an instance of a Writable stream that will receive the uploaded file data. With this
         * option, you can have any custom behavior regarding where the uploaded file data will be
         * streamed for. If you are looking to write the file uploaded in other types of cloud storages
         * (AWS S3, Azure blob storage, Google cloud storage) or private file storage, this is the option
         * you're looking for. When this option is defined the default behavior of writing the file in the
         * host machine file system is lost.
         *
         * @default null
         */
        fileWriteStreamHandler?: (() => void) | undefined;
GrosSacASac commented 2 years ago

You're right, it should return a writable stream CC https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56925 , @gboer

gboer commented 2 years ago

are you using 2.x or 1.x @pierznj ? I'll have a look to see if I can fix this tomorrow.

pierznj commented 2 years ago

2.x @gboer. Thank you!

gboer commented 2 years ago

PR is up! Might take some time before it's reviewed, merged, and released. So a bit of patience please :)

gboer commented 2 years ago

Version 2.0.1 of @types/formidable is available @pierznj. Good luck!

crivera commented 1 year ago

Hi

I noticed that the type is the following:

fileWriteStreamHandler?: (() => Writable) | undefined;

But isn't there the formidable.File passed in?

image
gboer commented 1 year ago

@crivera , seems to be indeed incorrect. It was reported before in #821 apparently. I'll have a look to see if I can fix it next week.

crivera commented 1 year ago

Awesome thank you!

gboer commented 1 year ago

PR is up here: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65215 @crivera . Just needs an approval of a DT maintainer and then it can be released. Might take a day or 2 before it is released/usable.

gboer commented 1 year ago

it's released as version 2.0.6 @crivera :)