How to use Promise.all() with Typescript

前端 未结 6 2048
旧时难觅i
旧时难觅i 2020-12-08 18:27

Here is what I want to do:

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


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 18:53

    At least from TypeScript 2.7.1 onwards, the compiler seems to resolve the types without help, with a syntax like this:

    Promise.all([fooPromise, barPromise]).then(([foo, bar]) => {
      // compiler correctly warns if someField not found from foo's type
      console.log(foo.someField);
    });
    

    Hat tip: @JamieBirch (from comment to @AndrewKirkegaard's answer)

提交回复
热议问题