【发布时间】:2018-10-26 21:48:19
【问题描述】:
没有Promise.all 和Array.prototype.map,有没有更简单的方法在 Typescript 中表达这种语法?
const items = [...];
await Promise.all(items.map(async item => {
doSomething(item);
const result = await doSomethingAsync(item);
doSomethingMore(result, item);
});
【问题讨论】:
-
没有。为什么你觉得不够简单?
-
如果你想同时做所有的承诺,你必须使用
Promise.all -
我认为记住使用
.map -
@DanielA.White 我认为 typescript 没有任何类型的数组理解
-
@DanielA.White 除了
map之外,您会使用什么来创建承诺数组?
标签: typescript promise async-await