I have a line of code that looks like:
isFullscreen = !!document["fullscreenElement"];
Flow is giving me the error:
169: isFullscreen = !!document["fullscreenElement"];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ access of computed property/element. Indexable signature not found in
169: isFullscreen = !!document["fullscreenElement"];
^^^^^^^^ Document
However, this code works fine in the browser. Is there something wrong with the builtin document type in flow or am I doing it wrong?
To index an object with object[...] syntax ("access of computed property" in Flow) it has to be declared with an index signature like [key: string]: value (see here). The Document class in Flow isn't declared with an index signature, so you can't use object[...] syntax on it.
I'd suggest that Flow _should_ support computed properties on Document, since it works at runtime, but I'm having trouble finding out what the values are supposed to be. Are they form elements indexed by name? If so, you should probably just use document.forms.namedItem(...) instead.
Maybe related: https://github.com/l20n/l20n.js/blob/1ad935c5a00c6529411c76d5b1544ed8a2a45c16/docs/bindings.md creates a document.l10n element – is it not possible to have that pass flow?
got same error even with type Array
Duplicate of #4014
Most helpful comment
To index an object with
object[...]syntax ("access of computed property" in Flow) it has to be declared with an index signature like[key: string]: value(see here). The Document class in Flow isn't declared with an index signature, so you can't useobject[...]syntax on it.I'd suggest that Flow _should_ support computed properties on
Document, since it works at runtime, but I'm having trouble finding out what the values are supposed to be. Are they form elements indexed by name? If so, you should probably just usedocument.forms.namedItem(...)instead.