【发布时间】:2020-12-03 04:17:46
【问题描述】:
我有以下函数调用
this.component.getXML({ format: true }, (error, currentXML) => {
if (error) {
console.error(error.message);
}
// do something with currentXML
});
但是我想用asyncawait来解决一个任务,为了做到这一点,我做了以下
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);
}
}
这行得通。我的问题是,在尝试构建 blob const blob = new Blob([currentXML], { type: "text/xml" }); 时,它给了我这个错误消息
Type 'unknown' is not assignable to type 'BlobPart'
Type '{}' is missing the following properties from type 'Blob': size, type, arrayBuffer, slice, and 2 more.
调用const currentXML = await promise;的输出是一个字符串,我尝试过明确定义但错误依旧
感谢您的评论。
【问题讨论】:
标签: javascript typescript angular10