Skip to content

lib Fix Part 1/6 – WeakMap constructor #50449

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Feb 28, 2023
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
2 changes: 1 addition & 1 deletion src/lib/es2015.collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ interface WeakMap<K extends object, V> {
}

interface WeakMapConstructor {
new <K extends object = object, V = any>(entries?: readonly [K, V][] | null): WeakMap<K, V>;
new <K extends object = object, V = any>(entries?: readonly (readonly [K, V])[] | null): WeakMap<K, V>;
readonly prototype: WeakMap<object, any>;
}
declare var WeakMap: WeakMapConstructor;
Expand Down
9 changes: 6 additions & 3 deletions tests/baselines/reference/mapConstructorOnReadonlyTuple.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//// [mapConstructorOnReadonlyTuple.ts]
const pairs = [['1', 1], ['2', 2]] as const
new Map(pairs);
const pairs = [[{}, 1], [{}, 2]] as const;
new Map(pairs);
new WeakMap(pairs);


//// [mapConstructorOnReadonlyTuple.js]
const pairs = [['1', 1], ['2', 2]];
const pairs = [[{}, 1], [{}, 2]];
new Map(pairs);
new WeakMap(pairs);
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
=== tests/cases/compiler/mapConstructorOnReadonlyTuple.ts ===
const pairs = [['1', 1], ['2', 2]] as const
const pairs = [[{}, 1], [{}, 2]] as const;
>pairs : Symbol(pairs, Decl(mapConstructorOnReadonlyTuple.ts, 0, 5))
>const : Symbol(const)

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

new WeakMap(pairs);
>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, --, --))
>pairs : Symbol(pairs, Decl(mapConstructorOnReadonlyTuple.ts, 0, 5))

25 changes: 15 additions & 10 deletions tests/baselines/reference/mapConstructorOnReadonlyTuple.types
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
=== tests/cases/compiler/mapConstructorOnReadonlyTuple.ts ===
const pairs = [['1', 1], ['2', 2]] as const
>pairs : readonly [readonly ["1", 1], readonly ["2", 2]]
>[['1', 1], ['2', 2]] as const : readonly [readonly ["1", 1], readonly ["2", 2]]
>[['1', 1], ['2', 2]] : readonly [readonly ["1", 1], readonly ["2", 2]]
>['1', 1] : readonly ["1", 1]
>'1' : "1"
const pairs = [[{}, 1], [{}, 2]] as const;
>pairs : readonly [readonly [{}, 1], readonly [{}, 2]]
>[[{}, 1], [{}, 2]] as const : readonly [readonly [{}, 1], readonly [{}, 2]]
>[[{}, 1], [{}, 2]] : readonly [readonly [{}, 1], readonly [{}, 2]]
>[{}, 1] : readonly [{}, 1]
>{} : {}
>1 : 1
>['2', 2] : readonly ["2", 2]
>'2' : "2"
>[{}, 2] : readonly [{}, 2]
>{} : {}
>2 : 2

new Map(pairs);
>new Map(pairs) : Map<"1" | "2", 1 | 2>
>new Map(pairs) : Map<{}, 1 | 2>
>Map : MapConstructor
>pairs : readonly [readonly ["1", 1], readonly ["2", 2]]
>pairs : readonly [readonly [{}, 1], readonly [{}, 2]]

new WeakMap(pairs);
>new WeakMap(pairs) : WeakMap<{}, 1 | 2>
>WeakMap : WeakMapConstructor
>pairs : readonly [readonly [{}, 1], readonly [{}, 2]]

5 changes: 3 additions & 2 deletions tests/cases/compiler/mapConstructorOnReadonlyTuple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: es2015

const pairs = [['1', 1], ['2', 2]] as const
new Map(pairs);
const pairs = [[{}, 1], [{}, 2]] as const;
new Map(pairs);
new WeakMap(pairs);