关于一道ts数组map成元组的问题

Promise.all([{ a: 123 }, { a: "abc" }, { a: true }] ).then(res => res.map(item => item.a)).then(res => {
  console.log(res);
})

https://www.typescriptlang.or...
这个是测试链接

这里的res为什么是 (string | number | boolean)[] 而不是一个元组 求解 如果才能变成元组

阅读 2.5k
1 个回答

image.png

根据 Promise.all 的类型定义,它的返回类型是一个 Awaited 的数据数组,所以数组就对了。
如果你想要元组,怕是要显式类型转换了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题