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

FileUpload: Property objectURL does not exist on type File #7136

Closed
ewenjo opened this issue Sep 8, 2024 · 6 comments · Fixed by #7145 · May be fixed by leoo1992/GeradorQRCode#95
Closed

FileUpload: Property objectURL does not exist on type File #7136

ewenjo opened this issue Sep 8, 2024 · 6 comments · Fixed by #7145 · May be fixed by leoo1992/GeradorQRCode#95
Assignees
Labels
Typescript Issue or pull request is *only* related to TypeScript definition
Milestone

Comments

@ewenjo
Copy link
Contributor

ewenjo commented Sep 8, 2024

Describe the bug

Property objectURL does not exist on type File

image

Reproducer

https://stackblitz.com/edit/vitejs-vite-gc9s8d?file=src%2FApp.tsx

System Information

Blank

Steps to reproduce the behavior

1: Access fileupload files, such as with fileupload.getFiles()
2: Attempt to use file.objectURL property.

Expected behavior

Should be typed as a string

@ewenjo ewenjo added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 8, 2024
@melloware
Copy link
Member

@ewenjo the typing is correct as File which is a JS declaration of File.

/**
     * Gets the current files list.
     * @return {File[]} Current files.
     */
    public getFiles(): File[];

Node.js defines that File object as...

interface File extends _File {}
    var File: typeof globalThis extends {
        onmessage: any;
        File: infer T;
    } ? T
        : typeof import("node:buffer").File;

So it seems like the Node definition is out of date or incorrect.

@melloware melloware added Typescript Issue or pull request is *only* related to TypeScript definition and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 9, 2024
@ewenjo
Copy link
Contributor Author

ewenjo commented Sep 9, 2024

@ewenjo the typing is correct as File which is a JS declaration of File.

/**
     * Gets the current files list.
     * @return {File[]} Current files.
     */
    public getFiles(): File[];

Wouldn't the correct type be?

File & { objectURL?: string }

As the code is conditionally extending the File object with the objectURL property that otherwise doesn't exist in the spec. As shown here:

file.objectURL = window.URL.createObjectURL(file);

So it seems like the Node definition is out of date or incorrect.

I don't believe objectURL is something that should be defined in the node definition. It's unrelated and doesn't apply to all files.

@melloware
Copy link
Member

AHHH i see that is a custom property for use in FileUpload. Yeah it probably should be then... Want to submit a PR?

@ewenjo
Copy link
Contributor Author

ewenjo commented Sep 9, 2024

Sure, I might have some time later today

@melloware melloware changed the title Fileupload: Property objectURL does not exist on type File FileUpload: Property objectURL does not exist on type File Sep 9, 2024
@melloware
Copy link
Member

I think File is used in a few places in the fileupload.d.ts file so we may want to declare the type and re-use it in the multiple spots?

@ewenjo
Copy link
Contributor Author

ewenjo commented Sep 9, 2024

Yes, that was my thought as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typescript Issue or pull request is *only* related to TypeScript definition
Projects
None yet
2 participants