diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index 20b6920e0d6..f1fb454f980 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -137,7 +137,8 @@ interface ReadonlyMap { } interface MapConstructor { - new (iterable: Iterable): Map; + new(): Map; + new (iterable?: Iterable | null): Map; } interface WeakMap { } diff --git a/tests/baselines/reference/for-of39.errors.txt b/tests/baselines/reference/for-of39.errors.txt index c887c20ef4b..fc45150a38c 100644 --- a/tests/baselines/reference/for-of39.errors.txt +++ b/tests/baselines/reference/for-of39.errors.txt @@ -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): Map', gave the following error. + Overload 1 of 4, '(iterable?: Iterable): Map', gave the following error. Argument of type '([string, number] | [string, true])[]' is not assignable to parameter of type 'Iterable'. 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'. @@ -9,7 +9,7 @@ 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', gave the following error. + Overload 2 of 4, '(entries?: readonly (readonly [string, boolean])[]): Map', gave the following error. Type 'number' is not assignable to type 'boolean'. @@ -17,7 +17,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of39.ts(1,11): error TS2769: No var map = new Map([["", true], ["", 0]]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2769: No overload matches this call. -!!! error TS2769: Overload 1 of 3, '(iterable: Iterable): Map', gave the following error. +!!! error TS2769: Overload 1 of 4, '(iterable?: Iterable): Map', gave the following error. !!! error TS2769: Argument of type '([string, number] | [string, true])[]' is not assignable to parameter of type 'Iterable'. !!! 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'. @@ -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', gave the following error. +!!! error TS2769: Overload 2 of 4, '(entries?: readonly (readonly [string, boolean])[]): Map', gave the following error. !!! error TS2769: Type 'number' is not assignable to type 'boolean'. for (var [k, v] of map) { k; diff --git a/tests/baselines/reference/iterableArrayPattern28.errors.txt b/tests/baselines/reference/iterableArrayPattern28.errors.txt index b47f3b2c993..b56659f48b9 100644 --- a/tests/baselines/reference/iterableArrayPattern28.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern28.errors.txt @@ -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): Map', gave the following error. + Overload 1 of 4, '(iterable?: Iterable): Map', gave the following error. Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'Iterable'. 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'. @@ -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', gave the following error. + Overload 2 of 4, '(entries?: readonly (readonly [string, number])[]): Map', gave the following error. Type 'boolean' is not assignable to type 'number'. @@ -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): Map', gave the following error. +!!! error TS2769: Overload 1 of 4, '(iterable?: Iterable): Map', gave the following error. !!! error TS2769: Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'Iterable'. !!! 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'. @@ -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', gave the following error. +!!! error TS2769: Overload 2 of 4, '(entries?: readonly (readonly [string, number])[]): Map', gave the following error. !!! error TS2769: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/mapConstructor.js b/tests/baselines/reference/mapConstructor.js new file mode 100644 index 00000000000..bb0b9e0697c --- /dev/null +++ b/tests/baselines/reference/mapConstructor.js @@ -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); diff --git a/tests/baselines/reference/mapConstructor.symbols b/tests/baselines/reference/mapConstructor.symbols new file mode 100644 index 00000000000..a37ecb3b56c --- /dev/null +++ b/tests/baselines/reference/mapConstructor.symbols @@ -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)) + diff --git a/tests/baselines/reference/mapConstructor.types b/tests/baselines/reference/mapConstructor.types new file mode 100644 index 00000000000..6531580d8da --- /dev/null +++ b/tests/baselines/reference/mapConstructor.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/mapConstructor.ts === +new Map(); +>new Map() : Map +>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 +>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 +>Map : MapConstructor +>potentiallyNullIterable : Iterable<[string, number]> | null + diff --git a/tests/baselines/reference/newMap.types b/tests/baselines/reference/newMap.types index c00ff104407..ee684b26e00 100644 --- a/tests/baselines/reference/newMap.types +++ b/tests/baselines/reference/newMap.types @@ -1,5 +1,5 @@ === tests/cases/compiler/newMap.ts === new Map(); ->new Map() : Map +>new Map() : Map >Map : MapConstructor diff --git a/tests/cases/compiler/mapConstructor.ts b/tests/cases/compiler/mapConstructor.ts new file mode 100644 index 00000000000..7d1124579e6 --- /dev/null +++ b/tests/cases/compiler/mapConstructor.ts @@ -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); \ No newline at end of file