Skip to content
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.iterable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ interface ReadonlyMap<K, V> {
}

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

interface WeakMap<K extends object, V> { }
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/for-of39.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/es6/for-ofStatements/for-of39.ts(1,11): error TS2769: No overload matches this call.
Overload 1 of 3, '(iterable: Iterable<readonly [string, boolean]>): Map<string, boolean>', gave the following error.
Overload 1 of 4, '(iterable?: Iterable<readonly [string, boolean]>): Map<string, boolean>', gave the following error.
Argument of type '([string, number] | [string, true])[]' is not assignable to parameter of type 'Iterable<readonly [string, boolean]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<[string, number] | [string, true], any>' is not assignable to type 'IteratorResult<readonly [string, boolean], any>'.
Expand All @@ -9,15 +9,15 @@ tests/cases/conformance/es6/for-ofStatements/for-of39.ts(1,11): error TS2769: No
Type '[string, number]' is not assignable to type 'readonly [string, boolean]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type 'number' is not assignable to type 'boolean'.
Overload 2 of 3, '(entries?: readonly (readonly [string, boolean])[]): Map<string, boolean>', gave the following error.
Overload 2 of 4, '(entries?: readonly (readonly [string, boolean])[]): Map<string, boolean>', gave the following error.
Type 'number' is not assignable to type 'boolean'.


==== tests/cases/conformance/es6/for-ofStatements/for-of39.ts (1 errors) ====
var map = new Map([["", true], ["", 0]]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 3, '(iterable: Iterable<readonly [string, boolean]>): Map<string, boolean>', gave the following error.
!!! error TS2769: Overload 1 of 4, '(iterable?: Iterable<readonly [string, boolean]>): Map<string, boolean>', gave the following error.
!!! error TS2769: Argument of type '([string, number] | [string, true])[]' is not assignable to parameter of type 'Iterable<readonly [string, boolean]>'.
!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
!!! error TS2769: Type 'IteratorResult<[string, number] | [string, true], any>' is not assignable to type 'IteratorResult<readonly [string, boolean], any>'.
Expand All @@ -27,7 +27,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of39.ts(1,11): error TS2769: No
!!! error TS2769: Type '[string, number]' is not assignable to type 'readonly [string, boolean]'.
!!! error TS2769: Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2769: Type 'number' is not assignable to type 'boolean'.
!!! error TS2769: Overload 2 of 3, '(entries?: readonly (readonly [string, boolean])[]): Map<string, boolean>', gave the following error.
!!! error TS2769: Overload 2 of 4, '(entries?: readonly (readonly [string, boolean])[]): Map<string, boolean>', gave the following error.
!!! error TS2769: Type 'number' is not assignable to type 'boolean'.
for (var [k, v] of map) {
k;
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/iterableArrayPattern28.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,24): error TS2769: No overload matches this call.
Overload 1 of 3, '(iterable: Iterable<readonly [string, number]>): Map<string, number>', gave the following error.
Overload 1 of 4, '(iterable?: Iterable<readonly [string, number]>): Map<string, number>', gave the following error.
Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'Iterable<readonly [string, number]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<[string, number] | [string, boolean], any>' is not assignable to type 'IteratorResult<readonly [string, number], any>'.
Expand All @@ -9,7 +9,7 @@ tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,24): error
Type '[string, boolean]' is not assignable to type 'readonly [string, number]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type 'boolean' is not assignable to type 'number'.
Overload 2 of 3, '(entries?: readonly (readonly [string, number])[]): Map<string, number>', gave the following error.
Overload 2 of 4, '(entries?: readonly (readonly [string, number])[]): Map<string, number>', gave the following error.
Type 'boolean' is not assignable to type 'number'.


Expand All @@ -18,7 +18,7 @@ tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,24): error
takeFirstTwoEntries(...new Map([["", 0], ["hello", true]]));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 3, '(iterable: Iterable<readonly [string, number]>): Map<string, number>', gave the following error.
!!! error TS2769: Overload 1 of 4, '(iterable?: Iterable<readonly [string, number]>): Map<string, number>', gave the following error.
!!! error TS2769: Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'Iterable<readonly [string, number]>'.
!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
!!! error TS2769: Type 'IteratorResult<[string, number] | [string, boolean], any>' is not assignable to type 'IteratorResult<readonly [string, number], any>'.
Expand All @@ -28,5 +28,5 @@ tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,24): error
!!! error TS2769: Type '[string, boolean]' is not assignable to type 'readonly [string, number]'.
!!! error TS2769: Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2769: Type 'boolean' is not assignable to type 'number'.
!!! error TS2769: Overload 2 of 3, '(entries?: readonly (readonly [string, number])[]): Map<string, number>', gave the following error.
!!! error TS2769: Overload 2 of 4, '(entries?: readonly (readonly [string, number])[]): Map<string, number>', gave the following error.
!!! error TS2769: Type 'boolean' is not assignable to type 'number'.
16 changes: 16 additions & 0 deletions tests/baselines/reference/mapConstructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [mapConstructor.ts]
new Map();

const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
new Map(potentiallyUndefinedIterable);

const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
new Map(potentiallyNullIterable);

//// [mapConstructor.js]
"use strict";
new Map();
const potentiallyUndefinedIterable = [['1', 1], ['2', 2]];
new Map(potentiallyUndefinedIterable);
const potentiallyNullIterable = [['1', 1], ['2', 2]];
new Map(potentiallyNullIterable);
20 changes: 20 additions & 0 deletions tests/baselines/reference/mapConstructor.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== tests/cases/compiler/mapConstructor.ts ===
new Map();
>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, --, --))

const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
>potentiallyUndefinedIterable : Symbol(potentiallyUndefinedIterable, Decl(mapConstructor.ts, 2, 5))
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))

new Map(potentiallyUndefinedIterable);
>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, --, --))
>potentiallyUndefinedIterable : Symbol(potentiallyUndefinedIterable, Decl(mapConstructor.ts, 2, 5))

const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
>potentiallyNullIterable : Symbol(potentiallyNullIterable, Decl(mapConstructor.ts, 5, 5))
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))

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

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

const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
>potentiallyUndefinedIterable : Iterable<[string, number]> | undefined
>[['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined : Iterable<[string, number]> | undefined
>[['1', 1], ['2', 2]] : [string, number][]
>['1', 1] : [string, number]
>'1' : "1"
>1 : 1
>['2', 2] : [string, number]
>'2' : "2"
>2 : 2

new Map(potentiallyUndefinedIterable);
>new Map(potentiallyUndefinedIterable) : Map<string, number>
>Map : MapConstructor
>potentiallyUndefinedIterable : Iterable<[string, number]> | undefined

const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
>potentiallyNullIterable : Iterable<[string, number]> | null
>[['1', 1], ['2', 2]] as Iterable<[string, number]> | null : Iterable<[string, number]> | null
>[['1', 1], ['2', 2]] : [string, number][]
>['1', 1] : [string, number]
>'1' : "1"
>1 : 1
>['2', 2] : [string, number]
>'2' : "2"
>2 : 2
>null : null

new Map(potentiallyNullIterable);
>new Map(potentiallyNullIterable) : Map<string, number>
>Map : MapConstructor
>potentiallyNullIterable : Iterable<[string, number]> | null

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

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

new Map();

const potentiallyUndefinedIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | undefined;
new Map(potentiallyUndefinedIterable);

const potentiallyNullIterable = [['1', 1], ['2', 2]] as Iterable<[string, number]> | null;
new Map(potentiallyNullIterable);