我Promise.all
适用于所有promise<void>
这样的
var actionList = new Array<Promise<void>>();
actionList.push(PluginService.InstallExtension(element, en.ExtensionFolder)
.then(function () {
addedExtensions.push(element);
var name = element.publisher + '.' + element.name + '-' + element.version;
//vscode.window.showInformationMessage("Extension " + name + " installed Successfully");
}));
Promise.all(actionList).then(function () {
// all resolved
}).catch(function (e) {
console.error(e);
});
我想在Promise<boolean>
actionList
我如何添加打字稿?
答案 0 :(得分:2)
在type参数上使用union type并指定它可以是void或布尔值:
var actionList = new Array<Promise<void | boolean>>();
// example of compiling code:
actionList.push(new Promise<void>((resolve, reject) => {}));
actionList.push(new Promise<boolean>((resolve, reject) => {}));