2016-08-28 4 views
2

I Promise.all haben, dieWie Leere Versprechen und eine andere Art Versprechen einzelne Versprechen legen Alle Array

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 Promise<boolean> in actionList

Wie ich hinzufügen in kann hinzufügen möchten auf allen promise<void> wie diese funktioniert Typoskript?

Antwort

1

ein union type auf dem Typparameter verwenden und angeben, dass es leer sein kann oder ein 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) => {}));