Skip to content

Commit 5739445

Browse files
lib Fix Part 1/6 – WeakMap constructor (#50449)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent 0e357f5 commit 5739445

5 files changed

+30
-17
lines changed

src/lib/es2015.collection.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ interface WeakMap<K extends object, V> {
6464
}
6565

6666
interface WeakMapConstructor {
67-
new <K extends object = object, V = any>(entries?: readonly [K, V][] | null): WeakMap<K, V>;
67+
new <K extends object = object, V = any>(entries?: readonly (readonly [K, V])[] | null): WeakMap<K, V>;
6868
readonly prototype: WeakMap<object, any>;
6969
}
7070
declare var WeakMap: WeakMapConstructor;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//// [mapConstructorOnReadonlyTuple.ts]
2-
const pairs = [['1', 1], ['2', 2]] as const
3-
new Map(pairs);
2+
const pairs = [[{}, 1], [{}, 2]] as const;
3+
new Map(pairs);
4+
new WeakMap(pairs);
5+
46

57
//// [mapConstructorOnReadonlyTuple.js]
6-
const pairs = [['1', 1], ['2', 2]];
8+
const pairs = [[{}, 1], [{}, 2]];
79
new Map(pairs);
10+
new WeakMap(pairs);
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
=== tests/cases/compiler/mapConstructorOnReadonlyTuple.ts ===
2-
const pairs = [['1', 1], ['2', 2]] as const
2+
const pairs = [[{}, 1], [{}, 2]] as const;
33
>pairs : Symbol(pairs, Decl(mapConstructorOnReadonlyTuple.ts, 0, 5))
44
>const : Symbol(const)
55

66
new Map(pairs);
77
>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, --, --))
88
>pairs : Symbol(pairs, Decl(mapConstructorOnReadonlyTuple.ts, 0, 5))
99

10+
new WeakMap(pairs);
11+
>WeakMap : Symbol(WeakMap, 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, --, --))
12+
>pairs : Symbol(pairs, Decl(mapConstructorOnReadonlyTuple.ts, 0, 5))
13+
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
=== tests/cases/compiler/mapConstructorOnReadonlyTuple.ts ===
2-
const pairs = [['1', 1], ['2', 2]] as const
3-
>pairs : readonly [readonly ["1", 1], readonly ["2", 2]]
4-
>[['1', 1], ['2', 2]] as const : readonly [readonly ["1", 1], readonly ["2", 2]]
5-
>[['1', 1], ['2', 2]] : readonly [readonly ["1", 1], readonly ["2", 2]]
6-
>['1', 1] : readonly ["1", 1]
7-
>'1' : "1"
2+
const pairs = [[{}, 1], [{}, 2]] as const;
3+
>pairs : readonly [readonly [{}, 1], readonly [{}, 2]]
4+
>[[{}, 1], [{}, 2]] as const : readonly [readonly [{}, 1], readonly [{}, 2]]
5+
>[[{}, 1], [{}, 2]] : readonly [readonly [{}, 1], readonly [{}, 2]]
6+
>[{}, 1] : readonly [{}, 1]
7+
>{} : {}
88
>1 : 1
9-
>['2', 2] : readonly ["2", 2]
10-
>'2' : "2"
9+
>[{}, 2] : readonly [{}, 2]
10+
>{} : {}
1111
>2 : 2
1212

1313
new Map(pairs);
14-
>new Map(pairs) : Map<"1" | "2", 1 | 2>
14+
>new Map(pairs) : Map<{}, 1 | 2>
1515
>Map : MapConstructor
16-
>pairs : readonly [readonly ["1", 1], readonly ["2", 2]]
16+
>pairs : readonly [readonly [{}, 1], readonly [{}, 2]]
17+
18+
new WeakMap(pairs);
19+
>new WeakMap(pairs) : WeakMap<{}, 1 | 2>
20+
>WeakMap : WeakMapConstructor
21+
>pairs : readonly [readonly [{}, 1], readonly [{}, 2]]
1722

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: es2015
22

3-
const pairs = [['1', 1], ['2', 2]] as const
4-
new Map(pairs);
3+
const pairs = [[{}, 1], [{}, 2]] as const;
4+
new Map(pairs);
5+
new WeakMap(pairs);

0 commit comments

Comments
 (0)