Skip to content

Incorrect type declaration #9

@TakhirKudusov

Description

@TakhirKudusov

Hi!
I try to use your library and found out that the return type of useFileUpload has one mistake.
It's first element of returned array - FileUpload | [FileUpload].
This hook does not return tupple [FileUpload] when multiple is true. This hook return FileUpload[] and that's a big difference, because [FileUpload] can have only one element, not two or three, etc.

I fixed this for me in such manner:

uploadFile(
      {
        multiple: true,
        accept: ['image/jpeg', 'image/jpg', 'image/png'],
      },
      (files) => {
       // the fix is below
        const result = (files as FileUpload[]).map((el) => ({
          ...el,
          id: v1(),
        }));
      },
    );

But I think you can make type system for this library better. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions