I have this code:
private descargar<T>(url: string, type: "arraybuffer" | "document" | "blob" | "json" | "text"): Promise<T | null>{
return new Promise(function (resolve) {
// Get file name from url.
var xhr = new XMLHttpRequest();
xhr.responseType = type;
xhr.onload = function () {
resolve(xhr.response);
return;
};
xhr.onerror = ()=>resolve(null);
xhr.open("GET", url);
xhr.send();
})
}
And it gets called like this:
const response = await this.descargar<Blob>(url, "blob")
It's redundant because you need to specify Blob twice. What's the alternative?