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

Improve UploadyProps to allow undefined values #710

Closed
meshuamam opened this issue Jul 18, 2024 · 2 comments
Closed

Improve UploadyProps to allow undefined values #710

meshuamam opened this issue Jul 18, 2024 · 2 comments
Labels

Comments

@meshuamam
Copy link

Recommended - Check out the discussions area before opening a new issue.

Is your feature request related to a problem? Please describe.
When passing UploadyProps, the current types only allow either for a value to not exist (marked by ?), or for it to have a value which isn't undefined.

export interface UploadyProps extends NoDomUploadyProps {
    customInput?: boolean;
    inputFieldContainer?: HTMLElement;
    capture?: string;
    multiple?: boolean;
    accept?: string;
    webkitdirectory?: boolean;
    fileInputId?: string;
    noPortal?: boolean;
}

this means, that code that wraps Uploady with custom props, can't be written like this:

export function UploadArea<T extends UploadType>(props: {  accept?: string }) {
return (
<Uploady
      destination={{ url: 'https://example.com }}
      accept={props.accept}
...

because Typescript will complain with TS2375 that Type undefined is not assignable to type string

Instead, we must resort to this:

export function UploadArea<T extends UploadType>(props: {  accept?: string }) {
return (
<Uploady
      destination={{ url: 'https://example.com }}
      {...(props.accept && { accept: props.accept})}
...

Describe the solution you'd like
Change the UploadyProps to:

export interface UploadyProps extends NoDomUploadyProps {
    customInput?: boolean | undefined;
    inputFieldContainer?: HTMLElement | undefined;
    capture?: string | undefined;
    multiple?: boolean | undefined;
    accept?: string | undefined;
    webkitdirectory?: boolean | undefined;
    fileInputId?: string | undefined;
    noPortal?: boolean | undefined;
}
@yoavniran
Copy link
Collaborator

thanks @meshuamam !
Sounds good. I will try to get to it soon, or if you like, open a PR.

@yoavniran yoavniran added enhancement New feature or request good first issue Good for newcomers typings labels Jul 18, 2024
@yoavniran yoavniran added in-progress and removed good first issue Good for newcomers labels Jul 19, 2024
@yoavniran
Copy link
Collaborator

@meshuamam version 1.8.2 released with the suggested improvement.
Please let me know if there are any issues.

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

2 participants