Skip to content

v3.7.2 Promise.all (No overload matchs this call) with different promise types and more than 10 promises #35617

@WandersonAlves

Description

@WandersonAlves

TypeScript Version: v3.7.2

Search Terms:
Promise.all, No overload matchs this call
Expected behavior:
Use a variable number of promises in a Promise.all call
Actual behavior:
If we use more than 10 promises, and these promises return different types, the compiler throws a error

Related Issues:

Code

// This works!
(async () => {
    const a0: Promise<number> = Promise.resolve(0);
    const a1: Promise<string> = Promise.resolve('0');
    const a2: Promise<number> = Promise.resolve(0);
    const a3: Promise<number> = Promise.resolve(0);
    const a4: Promise<number> = Promise.resolve(0);
    const a5: Promise<number> = Promise.resolve(0);
    const a6: Promise<number> = Promise.resolve(0);
    const a7: Promise<number> = Promise.resolve(0);
    const a8: Promise<number> = Promise.resolve(0);
    const a9: Promise<number> = Promise.resolve(0);
    const result = await Promise.all([a0, a1, a2, a3, a4, a5, a6, a7, a8, a9]);
})();
// If we use more than 10 promises with diferent types in a Promise.all, Promise.all throws a error
/**
 * No overload matches this call.
  The last overload gave the following error.
    Argument of type '(Promise<number> | Promise<string>)[]' is not assignable to parameter of type 'Iterable<number | PromiseLike<number>>'.
      The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
        Type 'IteratorResult<Promise<number> | Promise<string>, any>' is not assignable to type 'IteratorResult<number | PromiseLike<number>, any>'.
          Type 'IteratorYieldResult<Promise<number> | Promise<string>>' is not assignable to type 'IteratorResult<number | PromiseLike<number>, any>'.
            Type 'IteratorYieldResult<Promise<number> | Promise<string>>' is not assignable to type 'IteratorYieldResult<number | PromiseLike<number>>'.
              Type 'Promise<number> | Promise<string>' is not assignable to type 'number | PromiseLike<number>'.
                Type 'Promise<string>' is not assignable to type 'number | PromiseLike<number>'.
                  Type 'Promise<string>' is not assignable to type 'PromiseLike<number>'.
                    Types of property 'then' are incompatible.
                      Type '<TResult1 = string, TResult2 = never>(onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = number, TResult2 = never>(onfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => PromiseLike<...>'.
                        Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
                          Types of parameters 'value' and 'value' are incompatible.
                            Type 'string' is not assignable to type 'number'.(2769)
input.ts(29, 6): The last overload is declared here.
 */
(async () => {
    const a0: Promise<number> = Promise.resolve(0);
    const a1: Promise<string> = Promise.resolve('0');
    const a2: Promise<number> = Promise.resolve(0);
    const a3: Promise<number> = Promise.resolve(0);
    const a4: Promise<number> = Promise.resolve(0);
    const a5: Promise<number> = Promise.resolve(0);
    const a6: Promise<number> = Promise.resolve(0);
    const a7: Promise<number> = Promise.resolve(0);
    const a8: Promise<number> = Promise.resolve(0);
    const a9: Promise<number> = Promise.resolve(0);
    const a10: Promise<number> = Promise.resolve(0);
    const result = await Promise.all([a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]);
})();
Output
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
// This works!
(() => __awaiter(void 0, void 0, void 0, function* () {
    const a0 = Promise.resolve(0);
    const a1 = Promise.resolve('0');
    const a2 = Promise.resolve(0);
    const a3 = Promise.resolve(0);
    const a4 = Promise.resolve(0);
    const a5 = Promise.resolve(0);
    const a6 = Promise.resolve(0);
    const a7 = Promise.resolve(0);
    const a8 = Promise.resolve(0);
    const a9 = Promise.resolve(0);
    const result = yield Promise.all([a0, a1, a2, a3, a4, a5, a6, a7, a8, a9]);
}))();
// If we use more than 10 promises with diferent types in a Promise.all, Promise.all throws a error
(() => __awaiter(void 0, void 0, void 0, function* () {
    const a0 = Promise.resolve(0);
    const a1 = Promise.resolve('0');
    const a2 = Promise.resolve(0);
    const a3 = Promise.resolve(0);
    const a4 = Promise.resolve(0);
    const a5 = Promise.resolve(0);
    const a6 = Promise.resolve(0);
    const a7 = Promise.resolve(0);
    const a8 = Promise.resolve(0);
    const a9 = Promise.resolve(0);
    const a10 = Promise.resolve(0);
    const result = yield Promise.all([a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]);
}))();
Compiler Options
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "types": ["reflect-metadata", "swagger-express-ts"],
    "outDir": "dist",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "inlineSourceMap": true,
    "lib": ["es2017"]
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions