最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Add void Promise and other type promise to single Promise All Array - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Aug 28, 2016 at 17:48 Shan Khan asked Aug 28, 2016 at 15:23 Shan KhanShan Khan 10.4k18 gold badges69 silver badges114 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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 piling code:
actionList.push(new Promise<void>((resolve, reject) => {}));
actionList.push(new Promise<boolean>((resolve, reject) => {}));
发布评论

评论列表(0)

  1. 暂无评论