Skip to content

Incorrect type for FileWithPath's path and relativePath properties #115

@bthall16

Description

@bthall16

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

file-selector/src/file.ts

Lines 1233 to 1237 in f159a4a

export interface FileWithPath extends File {
readonly path?: string;
readonly handle?: FileSystemFileHandle;
readonly relativePath?: string;
}

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions