Skip to content

Dynamic import with Promise.all not working correctly.Β #45631

Closed
@vajahath

Description

@vajahath

When I put more than 10 dynamic imports on Promise.all typing breaks.

Bug Report

πŸ”Ž Search Terms

promise.all, dynamic import

πŸ•— Version & Regression Information

Spotted on ^4.4.2
Not sure about older versions.

⏯ Playground Link

Since this depends on importing modules, I'm attaching here the zip (manly 3 files, index.js, package.json, tsconfig.json) instead of playground link.

πŸ’» Code

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2020"
  },
  "compileOnSave": true,
  "include": ["src"]
}

When I put more than 10 entries on Promise.all, typing breaks.

// 10 entries - no problem
async function importTest() {
  const k = await Promise.all([
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("dayjs"),
    // import("lru-cache"),
    // import("lru-cache"),
  ] as const);
}

Now uncommenting 11th entry

async function importTest() {
  const k = await Promise.all([
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("lru-cache"),
    import("dayjs"),
    import("lru-cache"), // <- 11th entry
    // import("lru-cache"),
  ] as const);
}

resulting in
(attaching the zip here πŸ’Ό test-ts.zip)

src/issue-1.ts(2,9): error TS6133: 'k' is declared but its value is never read.
src/issue-1.ts(2,31): error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'readonly [Promise<typeof LRUCache>, Promise<typeof LRUCache>, Promise<typeof LRUCache>, Promise<typeof LRUCache>, Promise<typeof LRUCache>, ... 5 more ..., Promise<...>]' is not assignable to parameter of type 'Iterable<typeof LRUCache | PromiseLike<typeof LRUCache>>'.
      The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
        Type 'IteratorResult<Promise<typeof LRUCache> | Promise<typeof dayjs>, any>' is not assignable to type 'IteratorResult<typeof LRUCache | PromiseLike<typeof LRUCache>, any>'.
          Type 'IteratorYieldResult<Promise<typeof LRUCache> | Promise<typeof dayjs>>' is not assignable to type 'IteratorResult<typeof LRUCache | PromiseLike<typeof LRUCache>, any>'.
            Type 'IteratorYieldResult<Promise<typeof LRUCache> | Promise<typeof dayjs>>' is not assignable to type 'IteratorYieldResult<typeof LRUCache | PromiseLike<typeof LRUCache>>'.
              Type 'Promise<typeof LRUCache> | Promise<typeof dayjs>' is not assignable to type 'typeof LRUCache | PromiseLike<typeof LRUCache>'.
                Type 'Promise<typeof dayjs>' is not assignable to type 'typeof LRUCache | PromiseLike<typeof LRUCache>'.
                  Type 'Promise<typeof dayjs>' is not assignable to type 'PromiseLike<typeof LRUCache>'.
                    Types of property 'then' are incompatible.
                      Type '<TResult1 = typeof dayjs, TResult2 = never>(onfulfilled?: ((value: typeof dayjs) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = typeof LRUCache, TResult2 = never>(onfulfilled?: ((value: typeof LRUCache) => 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 'typeof dayjs' is not assignable to type 'typeof LRUCache'.
                              Type 'typeof dayjs' provides no match for the signature 'new <K, V>(options?: Options<K, V> | undefined): LRUCache<K, V>'.

Animation

πŸ™ Actual behavior

The compiler throws erros.

πŸ™‚ Expected behavior

There shouldn't be any errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions