I am creating a drag and drop interface. On drop, I get the native File. I need to extend this interface and include a few other information.
My first approach was using
interface AcceptedFile extends File {
acl: Acl,
disabled: boolean;
}
const toAcceptedFiles = (files: File[]): AcceptedFile[] => {
return files.map(file => {
return {
...file,
acl: Acl.Public,
disabled: false
}
});
}
However, the result of the function toAcceptedFiles, only contains the preview key from the File; all the blob, name, etc is gone. If I console.log the file inside the toAcceptedFiles, I can see all the keys.
The interesting thing is, the following interface works fine:
interface AcceptedFile {
file: File,
acl: Acl,
disabled: boolean;
}
Why is extending the File breaking it?
Fileobject while also expecting it to continue working. It’s likely that it has some internal properties that you simply don’t have access to (e.g. an memory pointer where the data is stored or something browser-specific). So you should probably just wrap it in a custom object instead of copying it to a custom type.