4

When I receive file drops in a Browser, I get a FileList object. What's the purpose of this type? As far as I can see, it is nearly the same as a Typescript File[] or a good old JavaScript array of file objects.

From what I could find, FileList is inferior since you cannot iterate over values or indices using one of

for (let file of files) {
  // read file
}

for (let index in files) {
  // read files[index]
}

I also don't see a history reason, since Array of File should have been around at least as long as FileList.

Am I missing something here?

Simon Warta
  • 10,850
  • 5
  • 40
  • 78

1 Answers1

5

Seems you are totally spot on - from the official specification:

Note: The FileList interface should be considered "at risk" since the general trend on the Web Platform is to replace such interfaces with the Array platform object in ECMAScript [ECMA-262]. In particular, this means syntax of the sort filelist.item(0) is at risk; most other programmatic use of FileList is unlikely to be affected by the eventual migration to an Array type.

This interface is rather old and quite similar to NodeList though the latter got modernized a bit.

artur grzesiak
  • 20,230
  • 5
  • 46
  • 56