Skip to content

No overload matches this call. Overload 1 of 4, '(iterable?: Iterable<readonly [unknown, unknown]> | null | undefined): Map<unknown, unknown>' #56120

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

Closed
albertkao9 opened this issue Oct 16, 2023 · 3 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@albertkao9
Copy link

albertkao9 commented Oct 16, 2023

🔎 Search Terms

"No overload matches this call" '(iterable?: Iterable<readonly [unknown, unknown]> | null | undefined): Map<unknown, unknown>'

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about this.

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYewdgzgLgBAlmADgV1gXhmApgdxgWQENEAKAbRjIHJjEAbLKgGioCcsATKgXScqoBGhMMMLMqATyx06IHDxjcAlAG4AsAChseIqTIA6QwhRRu+gLbESWMFFYSYaAHwwbdifvYA3LKwhYSJSCVIA

💻 Code

const input = new Map([ ['apple','red'], ['banana','yellow'] ]);
new Map([...input].map(entry => entry.reverse()));

🙁 Actual behavior

compile error:
No overload matches this call.
Overload 1 of 4, '(iterable?: Iterable<readonly [unknown, unknown]> | null | undefined): Map<unknown, unknown>', gave the following error.
Argument of type 'string[][]' is not assignable to parameter of type 'Iterable<readonly [unknown, unknown]>'.
The types returned by 'Symbol.iterator.next(...)' are incompatible between these types.
Type 'IteratorResult<string[], any>' is not assignable to type 'IteratorResult<readonly [unknown, unknown], any>'.
Type 'IteratorYieldResult<string[]>' is not assignable to type 'IteratorResult<readonly [unknown, unknown], any>'.
Type 'IteratorYieldResult<string[]>' is not assignable to type 'IteratorYieldResult<readonly [unknown, unknown]>'.
Type 'string[]' is not assignable to type 'readonly [unknown, unknown]'.
Target requires 2 element(s) but source may have fewer.
Overload 2 of 4, '(entries?: readonly (readonly [unknown, unknown])[] | null | undefined): Map<unknown, unknown>', gave the following error.
Argument of type 'string[][]' is not assignable to parameter of type 'readonly (readonly [unknown, unknown])[]'.
Type 'string[]' is not assignable to type 'readonly [unknown, unknown]'.

🙂 Expected behavior

No compile error

Additional information about the issue

This JavaScript code has no compile error at https://developer.mozilla.org/en-US/play .
i.e. It works.

@nmain
Copy link

nmain commented Oct 16, 2023

So you want .reverse() to change the type [T, U] into [U, T]? I can't find a specific issue for this, but this is closely related to things like #44309 and the other tickets linked from that.

Edit: And if you want it on reverse() and not just toReversed() I think you'd also need #41339?

@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Oct 16, 2023
@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Oct 16, 2023

There's currently no type constructor that reflects the type of reverse(), so we don't "know" how many elements are in it

@sukima
Copy link

sukima commented Jan 10, 2024

EDIT: never mind, Unable to reproduce in playground.

I ran into this error for a different reason. It has to do that TS expects the constructor for Map to take an Array when in fact per the spec it should be an Iterable. this line I think should be:

--- a	2024-01-09 20:14:25.893721728 -0500
+++ b	2024-01-09 20:15:27.910665078 -0500
@@ -29,7 +29,7 @@
 
 interface MapConstructor {
     new (): Map<any, any>;
-    new <K, V>(entries?: readonly (readonly [K, V])[] | null): Map<K, V>;
+    new <K, V>(entries?: readonly Iterable<readonly [K, V]> | null): Map<K, V>;
     readonly prototype: Map<any, any>;
 }
 declare var Map: MapConstructor;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

4 participants