Below is a very simplified version of some code that I'm passing to Google Closure Compiler:
"use strict";
var xhr = new XMLHttpRequest();
xhr.open("GET", "somefile", true);
xhr.responseType = "arraybuffer";
xhr.addEventListener(
'load',
function() {
var data = new Uint8Array(xhr.response);
/* ... do something ... */
}
);
This is basically an Ajax query to retrieve raw binary data and it is working as expected.
However, the compiler emits the following waing:
WARNING - actual parameter 1 of Uint8Array does not match formal parameter
found : *
required: (Array<number>|ArrayBuffer|ArrayBufferView|null|number)
var data = new Uint8Array(xhr.response);
^
I've spent some time trying to fix it with JSDoc directives, in order to explicitly define the type of 'xhr.response' as 'ArrayBuffer'.
For instance:
/** @property {ArrayBuffer} response */
var xhr = new XMLHttpRequest();
But nothing worked.
What DID finally work was to separate the variable declaration from its initialization, without adding any JSDoc directives:
var xhr;
xhr = new XMLHttpRequest();
No waing anymore.
The problem is that I don't get it. Why does it fix the problem? Was it really the correct thing to do?
