The definition of Promise.all does not align with the documentation provided

After examining the type definition of Promise.all, I noticed that there are 10 different definitions:

/**
 * Creates a Promise that is resolved with an array of results when all of the provided Promises
 * resolve, or rejected when any Promise is rejected.
 * @param values An array of Promises.
 * @returns A new Promise.
 */
all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;

I only showed the one with an array length of 3, but there are also versions like all<T1>, all<T1, T2>, and so on up to all<T1, T2, ..., T9, T10>.

Interestingly, this conflicts with the actual implementation of Promise.all, which can accept an input array exceeding the limit of 10:

let myPromise = num => Promise.resolve(num);
let myPromisesArray = (new Array(20))
  .fill()
  .map((_,i) => myPromise(i));
Promise.all(myPromisesArray).then(console.log)

While I consider myself decent at development, I defer to the expertise of the Microsoft developers who created the ES2015 type definition, leading me to question:

Why does the type definition for Promise.all not align with either its documentation or its actual functionality?

Answer №1

The general statement regarding up to 10 types in a non-uniform "tuples" is focused on arrays where different indices possess distinct independent types.

Additionally, there exists a declaration supporting a uniformly typed array of indefinite length:

all<T>(values: (T | PromiseLike<T>)[]): Promise<T[]>;

The declarations employing a tuple with a maximum length of 10 aim to address a substantial variety of use-cases and are necessitated by TypeScript's constraints as a language. This limitation arises from the fact that generic type inference for a tuple corresponds to a uniform array of a comprehensiveunion type, which would follow the aforementioned signature. Comparable generic declarations with limits on heterogeneous types are prevalent in other languages like C#. For instance, Action<> and Func<> uphold a constraint of 16 parameter types.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update the browser value using AJAX without the need to refresh the page

After retrieving a value from an XML file using ajax jquery, I encountered an issue. When I change the value in my XML file, it does not automatically update in the browser. <?xml version="1.0"?> <count><number>5</number></count ...

Is it possible to incorporate a retry mechanism for all methods within a class without the need to individually modify each method with additional code?

Is there a way in TypeScript to automatically apply a retry mechanism to all methods of a class, similar to how decorators work? This would be helpful so that developers won't have to manually add the retry logic to each method when new ones are added ...

Transferring information to the server with JSON in the Codeigniter framework

I have a JavaScript array (unitdata_set) that I need to send to the server for database processing using Codeigniter. JavaScript Array (unitdata_set):- [{"unit_id":"13","unit_title":"Testsdsdf","unit_max_occupancy":"3","unit_no":"1","unit_no_adults":"1", ...

Issue with Achieving Two-Way Binding in Angular 1.5 Component when using $ctrl

I am struggling with customizing some products using a component in my index.html. Ultimately, I need to calculate the total of selected products within the main controller "planosVoz" using two-way binding on the svaTotal property in the component control ...

An External Force is Disrupting My Jquery

Something seems off because everything was working perfectly fine until the FallingLeavesChristmas.min.js file stopped activating on this specific page. I initially thought it was an issue with the JavaScript itself, but that doesn't seem to be the ca ...

Can you explain the meaning of the second line in the code snippet?

Could you please explain the meaning of the second line in this code snippet? Is it a ternary operation, or something else entirely? And what is its significance? const user = await User.findOne({ email: req.body.email }); !user && res.stat ...

How can we delete a specific word from a string if it is found in an

Facing a seemingly simple problem that's proving tricky to solve. I have an array of product names and a sentence. The goal is to remove any product names from the sentence if they appear in it. const products = ["premium t-shirt", "t-shirt", "swea ...

Adding a baseURI to the image src in Angular 5 is causing issues with dynamically loading images

I am currently working on Angular 5.2.1 and I am facing an issue with loading an image from a server using its source URL. Here is the HTML code: <img #image [src]="cover" class="img-fluid" alt="NO image"> And here is the TypeScript code in image- ...

How is it possible that TypeScript does not provide a warning when a function is called with a different number of arguments than what is expected?

I am working on a vanilla JavaScript project in VS Code and have set up jsconfig.json. Here is an example of the code I am using: /** * @param {(arg: string) => void} nestedFunction */ function myFunction(nestedFunction) { // Some logic here } myFu ...

"An intermittent error is occurring with the jQuery webcam plugin, where a TypeError is being thrown stating that

Many times, I encounter the error stated in the subject line. The code snippet where this error occurs is within the else section of the function below: if ($('#clicktosnap').is('.disabled')) { alert ("Please enable the camera first, ...

Ways to transfer an array between two unrelated components using a shared service and BehaviorSubject in Angular

I have been facing difficulties passing an array from one component to another. The issue arises when the array is passed between components and ends up being empty. Despite seeing integers in the console, the array is being passed before any values are pu ...

What is the process of adding new fields to a model in TypeScript?

I have created a test.model.ts file: export interface ITransaction { description: string; transactionDate: string; isDebit: boolean; amount: number; debitAmount: string; creditAmount: string; } export class Transaction implements ...

The data stored in the variable cannot be accessed when calling it in a different method

Within my component, there are several methods including constructor(){...} and ngOnInit(){...}. I have declared a variable named values:any=[] in the class, and it is initialized with JSON data within a method called getData(). getData(){ this.service. ...

Injecting Dependencies in Angular 2 Without Using the Constructor

Exploring DI in Angular 2 has led me to implement a REST-Client using generic subtypes for concrete Datatypes like this: class RESTClient<T>{ constructor() { var inj = ReflectiveInjector.resolveAndCreate([HTTP_PROVIDERS]); this. ...

Assign a class to each element that the mouse hovers over while simultaneously clicking the mouse

I am faced with a scenario where I have three boxes: div { display: inline-block; width: 100px; height: 100px; border: 1px solid black; cursor: pointer; } div.selected, div:hover { background-color: red; color: white; } <div>A</d ...

I aim to customize the options of a dropdown list based on the selection of another dropdown

I am looking for a way to dynamically filter employees based on the department selected. Unfortunately, my knowledge of JavaScript and Ajax is limited. <div class="pure-checkbox ml-15"> <input id="checkbox2" name="sta ...

Pass JSON information from JavaScript AJAX to PHP

Currently, I am facing an issue while attempting to convert JSON data from JavaScript Ajax to PHP. An error message is displayed in the console and I am unsure about how to encode JSON into string format. Could you please guide me on what might be going wr ...

The close button on the Bootstrap dismissible alert is not visible, however, it still works correctly

I am currently utilizing dismissible alerts from Bootstrap for a login form. Everything is functioning as intended, with the exception of the Close button not displaying correctly, although it still works to dismiss the alert. As part of a course I am fol ...

Step-by-step guide on using the input tag to embed videos

I'm trying to embed a YouTube video using an iframe with an input tag, but for some reason, it's not working. Can you help me find the mistake? Here's the URL I entered: https://www.youtube.com/embed/G20AHZc_sfM This is the code in the body ...

Using the increment operator within a for loop in JavaScript

this code snippet causes an endless loop for (let i = 0; ++i;) { console.log(i) } the one that follows doesn't even run, why is that? for (let i = 0; i++;) { console.log(i) } I want a thorough understanding of this concept ...