如何将void Promise和其他类型Promise添加到单个Promise All数组

How to Add void Promise and other type promise to single Promise All Array

本文关键字:Promise 添加 单个 数组 All 类型 其他 void      更新时间:2023-09-26

我有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);
});

我想在actionList中加入Promise<boolean>

如何添加typescript?

在类型参数上使用联合类型,并指定它可以是void或boolean:

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) => {}));