You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! 👋🏼 Thanks a lot for implementing such a time-saver library!
When multiple prop is set to a falsy value, it is guaranteed to have exactly 1 file. However the typings on onDrop, onSelect and handleChange are widely typed to accommodate both cases. I'd expect them to be narrowed to accept File as their first argument when multiple is set to falsy value.
This could be achieved by having Props implemented as a generic type. Theoretically with something like:
typeFileFn<Mextendsboolean>=[boolean]extends[M]
? (arg: File|File[])=>void
: Mextendstrue
? (files: File[])=>void
: (file: File)=>void;typeProps<Mextendsboolean=false>={multiple?: M;onDrop?: FileFn<M>;onSelect?: FileFn<M>;handleChange?: FileFn<M>;// ... other props are omitted};functionFileUploader<Mextendsboolean=false>(props: Props<M>){return<>{/* ... code is omitted. Returning props instead, to be able to test */}</>;}
Hey! 👋🏼 Thanks a lot for implementing such a time-saver library!
When
multiple
prop is set to a falsy value, it is guaranteed to have exactly 1 file. However the typings ononDrop
,onSelect
andhandleChange
are widely typed to accommodate both cases. I'd expect them to be narrowed to acceptFile
as their first argument whenmultiple
is set to falsy value.Current types:
Expected narrowed types:
This could be achieved by having Props implemented as a generic type. Theoretically with something like:
Tests:
The text was updated successfully, but these errors were encountered: