file-selector icon indicating copy to clipboard operation
file-selector copied to clipboard

Incorrect type for `FileWithPath`'s `path` and `relativePath` properties

Open bthall16 opened this issue 1 year ago • 9 comments

The FileWithPath interface defines both its path and relativePath properties as optional:

https://github.com/react-dropzone/file-selector/blob/f159a4a034b942054ad18453fffa77fce7a6dc87/src/file.ts#L1233-L1237

indicating they could be undefined.

Looking at the implementation of toFileWithPath, however, it looks like there's no code path where either could be undefined. In particular, if file.path isn't already a string, it's set to a variable which is definitely a string by that point. relativePath is unconditionally set to the same variable mentioned above that's definitely a string.

This seems like a bug with the definition of FileWithPath: if neither path nor relativePath can ever be undefined, then marking them as optional isn't accurate.

I came across this as I was trying to figure out which situations could cause path or relativePath to be undefined so I could account for those situations in my web app.

bthall16 avatar Nov 18 '24 16:11 bthall16