Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better typings for Promise.all #39061

Closed
wants to merge 2 commits into from

Conversation

dubzzz
Copy link

@dubzzz dubzzz commented Jun 13, 2020

Currently Promise.all does not seem to properly type tuples containing more than 10 elements. For instance the following snippet is failing in TypeScript 3.9 (except if the user specifies Promise.all<string|number>, but the typings would be wrong in that case):

const a = Promise.all([
  Promise.resolve(1), Promise.resolve('string'),
  Promise.resolve(1), Promise.resolve('string'),
  Promise.resolve(1), Promise.resolve('string'),
  Promise.resolve(1), Promise.resolve('string'),
  Promise.resolve(1), Promise.resolve('string'),
  Promise.resolve(1), Promise.resolve('string'),
]) // fails to compile with TS 3.9 see playground link below

This PR suggests a way to properly type tuples containing more than 10 items.

See it in action https://www.typescriptlang.org/play/index.html#code/CYUwxgNghgTiAEkoGdnwLIE8AKMD2AtgJbIIDeAUPNfMgC5R1FjxQQQA8AKmiAB50QAO2Bo4UYHiERM8ANpQhmALrwAPvHGTpsxZjnKAfAAoAbmwCuIZAC54PAJR3chEiA5l5AaXhEh8AGsQTDwAM3tkZTseOS9VfkERNBdiUgAZIiCOP1CQGHgAVUN4AH5C+GjkWNUAX0MKGooKMCl6VngAXgwcfFSQADo2CGM5FLd+uGQ8CFMQYwBGBwAaeDHSCetp2eMAcnoYPwBzHYdlB2bWungAI07utYGhkfmVh42pmbm9ugOhY9Pzi0hG0WF0sG8nnIXvBvr9jmcLsCrsA7uDeuNIaoUKt0aQOEILARrnlDAZAZd4AgwT1XOtMaw0ASiXkyYi2uFqRD2CM3pMtnNFq9cQM+Z9dvsjiclrzNmLBTjaSLZdtYZLljKPtt5Rr+eKfmrpcL3rrtUbRSqJX8pTq5csFX1jWLVVb1WblQK7TaLfqXQimkC2lAHgBBdh3LnDUZuzUeoWKx3euEnBEBq7XENhroR55xh3mr6W-4pilgDMQcNGyHQ53w8lI+DAMsV+P07EPfGE4kwUnF+sgJtZyvcgwM+BMrus1PwUID+0Y4de2Nz9b5vVJ13x1emzfutcGxcLT3R3U163H2258ar08bvO77d3mN7l2GndPh9X3c3hFAA

Fixes #22469

@RyanCavanaugh, it is a follow up for my PR on Promise.race #27192 and #31117

@dubzzz dubzzz closed this Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: Allow array of > 10 values in argument of Promise.all() and Promise.race()
1 participant