One particular function call that I am dealing with is shown below
this.component.getXML({ format: true }, (error, currentXML) => {
if (error) {
console.error(error.message);
}
// do something with currentXML
});
However, I decide to leverage async
await
for a certain task. In order to achieve this, I made the following adjustments
async function someName() {
const promise = new Promise((resolve, reject) => {
this.component.getXML({ format: true }, (error, currentXML) => {
if (error) {
reject(error);
}
resolve(currentXML);
});
});
try {
const currentXML = await promise;
const blob = new Blob([currentXML], { type: "text/xml" });
const formData = new FormData();
formData.append("file", blob, "filename.xml");
} catch (error) {
console.error(error.message);
}
}
This approach works fine. The issue arises when attempting to create the blob using
const blob = new Blob([currentXML], { type: "text/xml" });
, resulting in an error message as follows:
Type 'unknown' is not assignable to type 'BlobPart'
Type '{}' is missing the following properties from type 'Blob': size, type, arrayBuffer, slice, and 2 more.
It seems that even though the output of
const currentXML = await promise;
is a string, explicitly defining it doesn't resolve the error.
Your insights would be greatly appreciated.