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

Un-consolidate overloads for Map and WeakMap #28052

Merged
1 commit merged into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/es2015.collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ interface Map<K, V> {
}

interface MapConstructor {
new <K = any, V = any>(entries?: ReadonlyArray<[K, V]> | null): Map<K, V>;
new(): Map<any, any>;
new<K, V>(entries?: ReadonlyArray<[K, V]> | null): Map<K, V>;
readonly prototype: Map<any, any>;
}
declare var Map: MapConstructor;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/es2015.iterable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ interface MapConstructor {
interface WeakMap<K extends object, V> { }

interface WeakMapConstructor {
new <K extends object = object, V = any>(iterable: Iterable<[K, V]>): WeakMap<K, V>;
new <K extends object, V>(iterable: Iterable<[K, V]>): WeakMap<K, V>;
Copy link
Contributor

@ExE-Boss ExE-Boss Nov 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this PR only changed this WeakMap constructor overload, #23551 has resurfaced once again, and the following is still valid:

new WeakMap<object>();

I’m fixing that in #41635 #56713.

}

interface Set<T> {
Expand Down
8 changes: 8 additions & 0 deletions tests/baselines/reference/newMap.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests/cases/compiler/newMap.ts(1,9): error TS2558: Expected 0-2 type arguments, but got 1.


==== tests/cases/compiler/newMap.ts (1 errors) ====
new Map<string>();
~~~~~~
!!! error TS2558: Expected 0-2 type arguments, but got 1.

6 changes: 6 additions & 0 deletions tests/baselines/reference/newMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [newMap.ts]
new Map<string>();


//// [newMap.js]
new Map();
4 changes: 4 additions & 0 deletions tests/baselines/reference/newMap.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/compiler/newMap.ts ===
new Map<string>();
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

5 changes: 5 additions & 0 deletions tests/baselines/reference/newMap.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/compiler/newMap.ts ===
new Map<string>();
>new Map<string>() : any
>Map : MapConstructor

2 changes: 2 additions & 0 deletions tests/cases/compiler/newMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @lib: es6
new Map<string>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should’ve also had a test case for:

new WeakMap<object>();

I’m fixing that in #41635.