Skip to content

Fix map constructor to accept readonly tuple #30381

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

Merged
merged 1 commit into from
Mar 13, 2019
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 @@ -10,7 +10,7 @@ interface Map<K, V> {

interface MapConstructor {
new(): Map<any, any>;
new<K, V>(entries?: ReadonlyArray<[K, V]> | null): Map<K, V>;
new<K, V>(entries?: ReadonlyArray<readonly [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 @@ -129,7 +129,7 @@ interface ReadonlyMap<K, V> {
}

interface MapConstructor {
new <K, V>(iterable: Iterable<[K, V]>): Map<K, V>;
new <K, V>(iterable: Iterable<readonly [K, V]>): Map<K, V>;
}

interface WeakMap<K extends object, V> { }
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/mapConstructorOnReadonlyTuple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [mapConstructorOnReadonlyTuple.ts]
const pairs = [['1', 1], ['2', 2]] as const
new Map(pairs);

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

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))

17 changes: 17 additions & 0 deletions tests/baselines/reference/mapConstructorOnReadonlyTuple.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== 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"
>1 : 1
>['2', 2] : readonly ["2", 2]
>'2' : "2"
>2 : 2

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

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

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