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

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

Closed
vajahath opened this issue Aug 30, 2021 · 2 comments
Closed

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

vajahath opened this issue Aug 30, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@vajahath
Copy link

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.

@andrewbranch
Copy link
Member

Duplicate of #22469, should be fixable with or after #45350

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Sep 1, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants