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

Interface 'FileWithPath' incorrectly extends 'File' #12

Closed
pmespresso opened this issue Jun 19, 2019 · 9 comments
Closed

Interface 'FileWithPath' incorrectly extends 'File' #12

pmespresso opened this issue Jun 19, 2019 · 9 comments
Labels

Comments

@pmespresso
Copy link

node_modules/file-selector/dist/file.d.ts:3:18 - error TS2430: Interface 'FileWithPath' incorrectly extends interface 'File'.
  Types of property 'path' are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.

export interface FileWithPath extends File {
                   ~~~~~~~~~~~~
@johnryan
Copy link

It looks like (in my case at least) this is caused by a conflicting type. I'm not sure if there's a way to specify that this is extending the lib.dom.d.ts definition rather than another.

@marcello3d
Copy link

I am also hitting this problem when using react-dropzone with electron when I try to upgrade to TypeScript 3.6.4.

Electron extends File to always have a path: string parameter:
https://github.com/electron/typescript-definitions/blob/b970d51b347746cc0399db2d758e5c5b795d6787/base/base_footer.ts#L9

Error I get:

/Users/marcello/Documents/github/project/node_modules/file-selector/dist/file.d.ts
ERROR in /Users/marcello/Documents/github/project/node_modules/file-selector/dist/file.d.ts(3,18):
TS2430: Interface 'FileWithPath' incorrectly extends interface 'File'.
  Types of property 'path' are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.

@pmespresso
Copy link
Author

pmespresso commented Oct 22, 2019

what works for me is just locking my react-dropzone version to 10.1.7, and this seems so far to be in line with the DefinitelyTyped types. if and when this changes, i'll bump it.

@jwoo0122
Copy link

Any update or solution about this typing problem?

@burtonator
Copy link
Contributor

Is everyone having this problem with Electron? To be fair I think it's Electron's fault maybe? I'm not sure if there's a way to say that something is JUST extended from 'dom' ... maybe import it as from 'dom' ?? I haven't tried that

@burtonator
Copy link
Contributor

There's a simple fix for this...

/** Provides information about files and allows JavaScript in a web page to access their content. */
interface DOMFile extends Blob {
    readonly lastModified: number;
    readonly name: string;
}

export interface FileWithPath extends DOMFile {
    readonly path?: string;
}

... this should work and avoid conflicts since typescript types are structural. FileWithPath will be compatible with File from DOM as I lifted the interface for DOMFile right from their namespace.

@burtonator
Copy link
Contributor

Sent a PR for this:

#30

@jll01
Copy link

jll01 commented Aug 5, 2020

I got the same issue, using react-dropzone 11, Typescript, and Electron.

Any news about your PR being merged?

@github-actions
Copy link

github-actions bot commented Sep 9, 2020

🎉 This issue has been resolved in version 0.1.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

6 participants