Tuple defined with as const
can't be passed to Promise.all
#31179
Labels
Bug
A bug in TypeScript
Domain: lib.d.ts
The issue relates to the different libraries shipped with TypeScript
Help Wanted
You can do this
Milestone
TypeScript Version:
3.4.3
3.4.5
3.5.0-dev.20190430
Search Terms:
Promise.all, array, tuple, as const
Code
Expected behavior:
Promise.all accepts a tuple of Promise objects. Code compiles.
Actual behavior:
An array of promises defined using
as const
can't be passed to Promise.all. With the latest ts build, I get the following compilation error:Playground Link:
https://www.typescriptlang.org/play/#src=function%20promiseValue%3CT%3E(value%3A%20T)%20%7B%0D%0A%20%20%20%20return%20Promise.resolve(value)%3B%0D%0A%7D%0D%0A%0D%0Aconst%20p1%20%3D%20Promise.resolve(1)%3B%0D%0Aconst%20p2%20%3D%20Promise.resolve('two')%3B%0D%0Aconst%20p3%20%3D%20Promise.resolve(true)%3B%0D%0A%0D%0A(async%20()%20%3D%3E%20%7B%0D%0A%20%20%20%20%2F%2F%20works%20fine%0D%0A%20%20%20%20%2F%2F%20let%20%5Bv1%2C%20v2%2C%20v3%5D%20%3D%20await%20Promise.all(%5Bp1%2C%20p2%2C%20p3%5D)%3B%0D%0A%0D%0A%20%20%20%20%2F%2F%20also%20fine%0D%0A%20%20%20%20%2F%2F%20const%20promises%20%3D%20%5Bp1%2C%20p2%2C%20p3%5D%20as%20%5Btypeof%20p1%2C%20typeof%20p2%2C%20typeof%20p3%5D%3B%0D%0A%0D%0A%20%20%20%20%2F%2F%20not%20fine%0D%0A%20%20%20%20const%20promises%20%3D%20%5Bp1%2C%20p2%2C%20p3%5D%20as%20const%3B%0D%0A%0D%0A%20%20%20%20let%20%5Bv1%2C%20v2%2C%20v3%5D%20%3D%20await%20Promise.all(promises)%3B%0D%0A%0D%0A%20%20%20%20%2F%2F%20quick%20type%20test%0D%0A%20%20%20%20v1.toExponential()%3B%0D%0A%20%20%20%20v2.toUpperCase()%3B%0D%0A%20%20%20%20let%20b%3A%20boolean%20%3D%20v3%3B%0D%0A%7D)()%3B%0D%0A%0D%0A
The text was updated successfully, but these errors were encountered: