【问题标题】:How to Add void Promise and other type promise to single Promise All Array如何将 void Promise 和其他类型的 Promise 添加到单个 Promise All Array
【发布时间】:2017-01-04 16:36:40
【问题描述】:

我有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&lt;boolean&gt;

我如何添加打字稿?

【问题讨论】:

    标签: javascript typescript promise


    【解决方案1】:

    在类型参数上使用 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) => {}));
    

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多