Shan Khan Shan Khan - 3 months ago 10
Javascript Question

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

I have

Promise.all
that works on all
promise<void>
like this

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


I want to add
Promise<boolean>
in
actionList


How i can add in typescript?

Answer

Use a union type on the type parameter and specify that it can be void or a 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) => {}));