Greg Gum Greg Gum - 7 months ago 54
TypeScript Question

How to use Promise.All with Typescript

Here is what I want to do:

Promise.all([aurelia.start(), entityManagerProvider.initialize()])
.then((results:Array<any>) => {
let aurelia: any = results[0];

arelia.start() returns an Aurelia type, while initialize() returns void.

The compiler gives an error message that the type cannot be inferred from the usage.

What I am trying to achieve is to get them to run at the same time, as they are both very long processes, then run


This is a weakness in the TypeScript and its Promise.all signature. Its generally best to have arrays with consistent types. You can do the following manually though:

let foo : [Promise<Aurelia>,Promise<void>] = [aurelia.start(), entityManagerProvider.initialize()];
Promise.all(foo).then((results:any[]) => {
    let aurelia: any = results[0];