I want to create an object which follows the following interface
interface FileList {
getter File? item(unsigned long index);
readonly attribute unsigned long length;
};
Eventually, I want to assign that object to the files
property of input type=file
HTML
element
The code I have written so far is
let file1 = new File(["foo"],"foo.txt");
let fl:FileList = {
item: function(index){
file1;
},
length: 1
} as FileList;
...
imageInputNE.files = fl ;
But I am getting error TypeError: Failed to set the 'files' property on 'HTMLInputElement': The provided value is not of type 'FileList'.
I tried creating a typescript
class as well but that doesn't work either
class MyFileList{
file:File;
length=1;
constructor(file:File){
this.file = file;
}
item(index):File|null {
return this.file;
}
}
...
let file1 = new File(["foo"],"foo.txt");
let fl:MyFileList = new MyFileList(file1);
imageInputNE.files = fl ;
How could I create an object of type FileList
?