Skip to content

Commit 7309c85

Browse files
committed
Add map constructor test.
This proves that the previous commit fixes #37779, as well as that new Map() still types as Map<any, any>.
1 parent 41677cd commit 7309c85

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [mapConstructor.ts]
2+
new Map();
3+
4+
const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
5+
new Map(potentiallyUndefinedIterable);
6+
7+
const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
8+
new Map(potentiallyNullIterable);
9+
10+
//// [mapConstructor.js]
11+
"use strict";
12+
new Map();
13+
const potentiallyUndefinedIterable = [['1', 1], ['2', 2]];
14+
new Map(potentiallyUndefinedIterable);
15+
const potentiallyNullIterable = [['1', 1], ['2', 2]];
16+
new Map(potentiallyNullIterable);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/mapConstructor.ts ===
2+
new Map();
3+
>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, --, --))
4+
5+
const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
6+
>potentiallyUndefinedIterable : Symbol(potentiallyUndefinedIterable, Decl(mapConstructor.ts, 2, 5))
7+
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))
8+
9+
new Map(potentiallyUndefinedIterable);
10+
>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, --, --))
11+
>potentiallyUndefinedIterable : Symbol(potentiallyUndefinedIterable, Decl(mapConstructor.ts, 2, 5))
12+
13+
const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
14+
>potentiallyNullIterable : Symbol(potentiallyNullIterable, Decl(mapConstructor.ts, 5, 5))
15+
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))
16+
17+
new Map(potentiallyNullIterable);
18+
>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, --, --))
19+
>potentiallyNullIterable : Symbol(potentiallyNullIterable, Decl(mapConstructor.ts, 5, 5))
20+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
=== tests/cases/compiler/mapConstructor.ts ===
2+
new Map();
3+
>new Map() : Map<any, any>
4+
>Map : MapConstructor
5+
6+
const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
7+
>potentiallyUndefinedIterable : Iterable<[string, number]> | undefined
8+
>[['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined : Iterable<[string, number]> | undefined
9+
>[['1', 1], ['2', 2]] : [string, number][]
10+
>['1', 1] : [string, number]
11+
>'1' : "1"
12+
>1 : 1
13+
>['2', 2] : [string, number]
14+
>'2' : "2"
15+
>2 : 2
16+
17+
new Map(potentiallyUndefinedIterable);
18+
>new Map(potentiallyUndefinedIterable) : Map<string, number>
19+
>Map : MapConstructor
20+
>potentiallyUndefinedIterable : Iterable<[string, number]> | undefined
21+
22+
const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
23+
>potentiallyNullIterable : Iterable<[string, number]> | null
24+
>[['1', 1], ['2', 2]] as Iterable<[string, number]> | null : Iterable<[string, number]> | null
25+
>[['1', 1], ['2', 2]] : [string, number][]
26+
>['1', 1] : [string, number]
27+
>'1' : "1"
28+
>1 : 1
29+
>['2', 2] : [string, number]
30+
>'2' : "2"
31+
>2 : 2
32+
>null : null
33+
34+
new Map(potentiallyNullIterable);
35+
>new Map(potentiallyNullIterable) : Map<string, number>
36+
>Map : MapConstructor
37+
>potentiallyNullIterable : Iterable<[string, number]> | null
38+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @strict: true
2+
// @target: es2015
3+
4+
new Map();
5+
6+
const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
7+
new Map(potentiallyUndefinedIterable);
8+
9+
const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
10+
new Map(potentiallyNullIterable);

0 commit comments

Comments
 (0)