diff --git a/tsc/internal/bundled/libs/lib.es2015.collection.d.ts b/tsc/internal/bundled/libs/lib.es2015.collection.d.ts index 225e918b76477..55399ad8ec1f1 100644 --- a/tsc/internal/bundled/libs/lib.es2015.collection.d.ts +++ b/tsc/internal/bundled/libs/lib.es2015.collection.d.ts @@ -49,6 +49,7 @@ interface Map { interface MapConstructor { new (): Map; new (entries?: readonly (readonly [K, V])[] | null): Map; + new (entries?: readonly KV[] | null): Map; readonly prototype: Map; } declare var Map: MapConstructor; diff --git a/tsc/internal/bundled/libs/lib.es2015.iterable.d.ts b/tsc/internal/bundled/libs/lib.es2015.iterable.d.ts index 7396a53feb8cf..650139576ddac 100644 --- a/tsc/internal/bundled/libs/lib.es2015.iterable.d.ts +++ b/tsc/internal/bundled/libs/lib.es2015.iterable.d.ts @@ -179,6 +179,7 @@ interface ReadonlyMap { interface MapConstructor { new (): Map; new (iterable?: Iterable | null): Map; + new (iterable?: Iterable | null): Map; } interface WeakMap {} diff --git a/tsc/testdata/baselines/reference/compiler/newMap.errors.txt b/tsc/testdata/baselines/reference/compiler/newMap.errors.txt index ac5cce1f5ed80..ec31222ec6a3e 100644 --- a/tsc/testdata/baselines/reference/compiler/newMap.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/newMap.errors.txt @@ -1,9 +1,9 @@ -newMap.ts(1,9): error TS2743: No overload expects 1 type arguments, but overloads do exist that expect either 0 or 2 type arguments. +newMap.ts(1,9): error TS2344: Type 'string' does not satisfy the constraint 'readonly [any, any]'. ==== newMap.ts (1 errors) ==== new Map(); ~~~~~~ -!!! error TS2743: No overload expects 1 type arguments, but overloads do exist that expect either 0 or 2 type arguments. +!!! error TS2344: Type 'string' does not satisfy the constraint 'readonly [any, any]'. new WeakMap(); \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/for-of39.errors.txt b/tsc/testdata/baselines/reference/conformance/for-of39.errors.txt deleted file mode 100644 index 9b25b5eb78a78..0000000000000 --- a/tsc/testdata/baselines/reference/conformance/for-of39.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -for-of39.ts(1,25): error TS2769: No overload matches this call. - The last overload gave the following error. - Type 'boolean' is not assignable to type 'number'. - - -==== for-of39.ts (1 errors) ==== - var map = new Map([["", true], ["", 0]]); - ~~~~ -!!! error TS2769: No overload matches this call. -!!! error TS2769: The last overload gave the following error. -!!! error TS2769: Type 'boolean' is not assignable to type 'number'. -!!! related TS2771 lib.es2015.collection.d.ts:--:--: The last overload is declared here. - for (var [k, v] of map) { - k; - v; - } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/for-of39.types b/tsc/testdata/baselines/reference/conformance/for-of39.types index 220f0474230f1..f42a6f133cdde 100644 --- a/tsc/testdata/baselines/reference/conformance/for-of39.types +++ b/tsc/testdata/baselines/reference/conformance/for-of39.types @@ -2,11 +2,11 @@ === for-of39.ts === var map = new Map([["", true], ["", 0]]); ->map : Map ->new Map([["", true], ["", 0]]) : Map +>map : Map +>new Map([["", true], ["", 0]]) : Map >Map : MapConstructor ->[["", true], ["", 0]] : ([string, number] | [string, boolean])[] ->["", true] : [string, boolean] +>[["", true], ["", 0]] : ([string, number] | [string, true])[] +>["", true] : [string, true] >"" : "" >true : true >["", 0] : [string, number] @@ -15,12 +15,12 @@ var map = new Map([["", true], ["", 0]]); for (var [k, v] of map) { >k : string ->v : number ->map : Map +>v : number | boolean +>map : Map k; >k : string v; ->v : number +>v : number | boolean } diff --git a/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.errors.txt b/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.errors.txt index 23d0eab3af01e..9fd23f7e97209 100644 --- a/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.errors.txt +++ b/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.errors.txt @@ -1,13 +1,14 @@ -iterableArrayPattern28.ts(2,52): error TS2769: No overload matches this call. - The last overload gave the following error. - Type 'boolean' is not assignable to type 'number'. +iterableArrayPattern28.ts(2,21): error TS2345: Argument of type '[string, number | boolean]' is not assignable to parameter of type '[string, number]'. + Type at position 1 in source is not compatible with type at position 1 in target. + Type 'number | boolean' is not assignable to type 'number'. + Type 'boolean' is not assignable to type 'number'. ==== iterableArrayPattern28.ts (1 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } takeFirstTwoEntries(...new Map([["", 0], ["hello", true]])); - ~~~~ -!!! error TS2769: No overload matches this call. -!!! error TS2769: The last overload gave the following error. -!!! error TS2769: Type 'boolean' is not assignable to type 'number'. -!!! related TS2771 lib.es2015.collection.d.ts:--:--: The last overload is declared here. \ No newline at end of file + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[string, number | boolean]' is not assignable to parameter of type '[string, number]'. +!!! error TS2345: Type at position 1 in source is not compatible with type at position 1 in target. +!!! error TS2345: Type 'number | boolean' is not assignable to type 'number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.types b/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.types index 2d836c6eab74d..b833ab983fece 100644 --- a/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.types +++ b/tsc/testdata/baselines/reference/conformance/iterableArrayPattern28.types @@ -11,14 +11,14 @@ function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } takeFirstTwoEntries(...new Map([["", 0], ["hello", true]])); >takeFirstTwoEntries(...new Map([["", 0], ["hello", true]])) : void >takeFirstTwoEntries : (...[[k1, v1], [k2, v2]]: [string, number][]) => void ->...new Map([["", 0], ["hello", true]]) : [string, number] ->new Map([["", 0], ["hello", true]]) : Map +>...new Map([["", 0], ["hello", true]]) : [string, number | boolean] +>new Map([["", 0], ["hello", true]]) : Map >Map : MapConstructor ->[["", 0], ["hello", true]] : ([string, number] | [string, boolean])[] +>[["", 0], ["hello", true]] : ([string, number] | [string, true])[] >["", 0] : [string, number] >"" : "" >0 : 0 ->["hello", true] : [string, boolean] +>["hello", true] : [string, true] >"hello" : "hello" >true : true diff --git a/tsc/testdata/baselines/reference/conformance/new-Map1.js b/tsc/testdata/baselines/reference/conformance/new-Map1.js new file mode 100644 index 0000000000000..53c665e92be81 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/new-Map1.js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/es6/mapConstruction/new-Map1.ts] //// + +//// [new-Map1.ts] +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-628802102 +const sample: Map = new Map([[1, 1], ["yes", 1]]); + +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-750412755 +function test(_a: Map) {} +test(new Map([["test" ,true] ,[1 ,false]])) + +// https://github.com/microsoft/TypeScript/issues/33611#issue-498858215 +const M1 = new Map([ + ['k', {a: 1, b: 'asd'}], + ['k', {a: 2, b: 'asd'}], +]); +const M2 = new Map([ + ...M1, + ['k', {a: 1}], +]); + +// Additional cases +const m1 = new Map([['num', 123], ['str', 'val1']]); +const m2 = new Map([['num', 456], ['str', 'val2']] as const); +const m3 = new Map([['num' as const, 456], ['str' as const, 'val2']]); + + +//// [new-Map1.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-628802102 +const sample = new Map([[1, 1], ["yes", 1]]); +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-750412755 +function test(_a) { } +test(new Map([["test", true], [1, false]])); +// https://github.com/microsoft/TypeScript/issues/33611#issue-498858215 +const M1 = new Map([ + ['k', { a: 1, b: 'asd' }], + ['k', { a: 2, b: 'asd' }], +]); +const M2 = new Map([ + ...M1, + ['k', { a: 1 }], +]); +// Additional cases +const m1 = new Map([['num', 123], ['str', 'val1']]); +const m2 = new Map([['num', 456], ['str', 'val2']]); +const m3 = new Map([['num', 456], ['str', 'val2']]); diff --git a/tsc/testdata/baselines/reference/conformance/new-Map1.symbols b/tsc/testdata/baselines/reference/conformance/new-Map1.symbols new file mode 100644 index 0000000000000..74a3315139ed7 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/new-Map1.symbols @@ -0,0 +1,61 @@ +//// [tests/cases/conformance/es6/mapConstruction/new-Map1.ts] //// + +=== new-Map1.ts === +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-628802102 +const sample: Map = new Map([[1, 1], ["yes", 1]]); +>sample : Symbol(sample, Decl(new-Map1.ts, 1, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) + +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-750412755 +function test(_a: Map) {} +>test : Symbol(test, Decl(new-Map1.ts, 1, 75)) +>_a : Symbol(_a, Decl(new-Map1.ts, 4, 14)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) + +test(new Map([["test" ,true] ,[1 ,false]])) +>test : Symbol(test, Decl(new-Map1.ts, 1, 75)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) + +// https://github.com/microsoft/TypeScript/issues/33611#issue-498858215 +const M1 = new Map([ +>M1 : Symbol(M1, Decl(new-Map1.ts, 8, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) + + ['k', {a: 1, b: 'asd'}], +>a : Symbol(a, Decl(new-Map1.ts, 9, 8)) +>b : Symbol(b, Decl(new-Map1.ts, 9, 13)) + + ['k', {a: 2, b: 'asd'}], +>a : Symbol(a, Decl(new-Map1.ts, 10, 8)) +>b : Symbol(b, Decl(new-Map1.ts, 10, 13)) + +]); +const M2 = new Map([ +>M2 : Symbol(M2, Decl(new-Map1.ts, 12, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) + + ...M1, +>M1 : Symbol(M1, Decl(new-Map1.ts, 8, 5)) + + ['k', {a: 1}], +>a : Symbol(a, Decl(new-Map1.ts, 14, 8)) + +]); + +// Additional cases +const m1 = new Map([['num', 123], ['str', 'val1']]); +>m1 : Symbol(m1, Decl(new-Map1.ts, 18, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) + +const m2 = new Map([['num', 456], ['str', 'val2']] as const); +>m2 : Symbol(m2, Decl(new-Map1.ts, 19, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) +>const : Symbol(const) + +const m3 = new Map([['num' as const, 456], ['str' as const, 'val2']]); +>m3 : Symbol(m3, Decl(new-Map1.ts, 20, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) +>const : Symbol(const) +>const : Symbol(const) + diff --git a/tsc/testdata/baselines/reference/conformance/new-Map1.types b/tsc/testdata/baselines/reference/conformance/new-Map1.types new file mode 100644 index 0000000000000..dcc7d379b50ec --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/new-Map1.types @@ -0,0 +1,119 @@ +//// [tests/cases/conformance/es6/mapConstruction/new-Map1.ts] //// + +=== new-Map1.ts === +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-628802102 +const sample: Map = new Map([[1, 1], ["yes", 1]]); +>sample : Map +>new Map([[1, 1], ["yes", 1]]) : Map +>Map : MapConstructor +>[[1, 1], ["yes", 1]] : ([string, number] | [number, number])[] +>[1, 1] : [number, number] +>1 : 1 +>1 : 1 +>["yes", 1] : [string, number] +>"yes" : "yes" +>1 : 1 + +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-750412755 +function test(_a: Map) {} +>test : (_a: Map) => void +>_a : Map + +test(new Map([["test" ,true] ,[1 ,false]])) +>test(new Map([["test" ,true] ,[1 ,false]])) : void +>test : (_a: Map) => void +>new Map([["test" ,true] ,[1 ,false]]) : Map +>Map : MapConstructor +>[["test" ,true] ,[1 ,false]] : ([string, true] | [number, false])[] +>["test" ,true] : [string, true] +>"test" : "test" +>true : true +>[1 ,false] : [number, false] +>1 : 1 +>false : false + +// https://github.com/microsoft/TypeScript/issues/33611#issue-498858215 +const M1 = new Map([ +>M1 : Map +>new Map([ ['k', {a: 1, b: 'asd'}], ['k', {a: 2, b: 'asd'}],]) : Map +>Map : MapConstructor +>[ ['k', {a: 1, b: 'asd'}], ['k', {a: 2, b: 'asd'}],] : [string, { a: number; b: string; }][] + + ['k', {a: 1, b: 'asd'}], +>['k', {a: 1, b: 'asd'}] : [string, { a: number; b: string; }] +>'k' : "k" +>{a: 1, b: 'asd'} : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>'asd' : "asd" + + ['k', {a: 2, b: 'asd'}], +>['k', {a: 2, b: 'asd'}] : [string, { a: number; b: string; }] +>'k' : "k" +>{a: 2, b: 'asd'} : { a: number; b: string; } +>a : number +>2 : 2 +>b : string +>'asd' : "asd" + +]); +const M2 = new Map([ +>M2 : Map +>new Map([ ...M1, ['k', {a: 1}],]) : Map +>Map : MapConstructor +>[ ...M1, ['k', {a: 1}],] : ([string, { a: number; b: string; }] | [string, { a: number; }])[] + + ...M1, +>...M1 : [string, { a: number; b: string; }] +>M1 : Map + + ['k', {a: 1}], +>['k', {a: 1}] : [string, { a: number; }] +>'k' : "k" +>{a: 1} : { a: number; } +>a : number +>1 : 1 + +]); + +// Additional cases +const m1 = new Map([['num', 123], ['str', 'val1']]); +>m1 : Map +>new Map([['num', 123], ['str', 'val1']]) : Map +>Map : MapConstructor +>[['num', 123], ['str', 'val1']] : ([string, string] | [string, number])[] +>['num', 123] : [string, number] +>'num' : "num" +>123 : 123 +>['str', 'val1'] : [string, string] +>'str' : "str" +>'val1' : "val1" + +const m2 = new Map([['num', 456], ['str', 'val2']] as const); +>m2 : Map<"num" | "str", "val2" | 456> +>new Map([['num', 456], ['str', 'val2']] as const) : Map<"num" | "str", "val2" | 456> +>Map : MapConstructor +>[['num', 456], ['str', 'val2']] as const : readonly [readonly ["num", 456], readonly ["str", "val2"]] +>[['num', 456], ['str', 'val2']] : readonly [readonly ["num", 456], readonly ["str", "val2"]] +>['num', 456] : readonly ["num", 456] +>'num' : "num" +>456 : 456 +>['str', 'val2'] : readonly ["str", "val2"] +>'str' : "str" +>'val2' : "val2" + +const m3 = new Map([['num' as const, 456], ['str' as const, 'val2']]); +>m3 : Map<"num" | "str", string | number> +>new Map([['num' as const, 456], ['str' as const, 'val2']]) : Map<"num" | "str", string | number> +>Map : MapConstructor +>[['num' as const, 456], ['str' as const, 'val2']] : (["num", number] | ["str", string])[] +>['num' as const, 456] : ["num", number] +>'num' as const : "num" +>'num' : "num" +>456 : 456 +>['str' as const, 'val2'] : ["str", string] +>'str' as const : "str" +>'str' : "str" +>'val2' : "val2" + diff --git a/tsc/testdata/baselines/reference/conformance/new-Map2.errors.txt b/tsc/testdata/baselines/reference/conformance/new-Map2.errors.txt new file mode 100644 index 0000000000000..54a1fa3dea806 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/new-Map2.errors.txt @@ -0,0 +1,17 @@ +new-Map2.ts(6,7): error TS7034: Variable 'a3' implicitly has type 'any[]' in some locations where its type cannot be determined. +new-Map2.ts(7,20): error TS7005: Variable 'a3' implicitly has an 'any[]' type. + + +==== new-Map2.ts (2 errors) ==== + const m1 = new Map([]); + + const a2: any[] = []; + const m2 = new Map(a2); + + const a3 = []; + ~~ +!!! error TS7034: Variable 'a3' implicitly has type 'any[]' in some locations where its type cannot be determined. + const m3 = new Map(a3); + ~~ +!!! error TS7005: Variable 'a3' implicitly has an 'any[]' type. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/new-Map2.js b/tsc/testdata/baselines/reference/conformance/new-Map2.js new file mode 100644 index 0000000000000..3139f2d165031 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/new-Map2.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/es6/mapConstruction/new-Map2.ts] //// + +//// [new-Map2.ts] +const m1 = new Map([]); + +const a2: any[] = []; +const m2 = new Map(a2); + +const a3 = []; +const m3 = new Map(a3); + + +//// [new-Map2.js] +"use strict"; +const m1 = new Map([]); +const a2 = []; +const m2 = new Map(a2); +const a3 = []; +const m3 = new Map(a3); diff --git a/tsc/testdata/baselines/reference/conformance/new-Map2.symbols b/tsc/testdata/baselines/reference/conformance/new-Map2.symbols new file mode 100644 index 0000000000000..2a082d8006ee6 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/new-Map2.symbols @@ -0,0 +1,23 @@ +//// [tests/cases/conformance/es6/mapConstruction/new-Map2.ts] //// + +=== new-Map2.ts === +const m1 = new Map([]); +>m1 : Symbol(m1, Decl(new-Map2.ts, 0, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) + +const a2: any[] = []; +>a2 : Symbol(a2, Decl(new-Map2.ts, 2, 5)) + +const m2 = new Map(a2); +>m2 : Symbol(m2, Decl(new-Map2.ts, 3, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) +>a2 : Symbol(a2, Decl(new-Map2.ts, 2, 5)) + +const a3 = []; +>a3 : Symbol(a3, Decl(new-Map2.ts, 5, 5)) + +const m3 = new Map(a3); +>m3 : Symbol(m3, Decl(new-Map2.ts, 6, 5)) +>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, --, --), Decl(lib.es2026.collection.d.ts, --, --)) +>a3 : Symbol(a3, Decl(new-Map2.ts, 5, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/new-Map2.types b/tsc/testdata/baselines/reference/conformance/new-Map2.types new file mode 100644 index 0000000000000..81aad9abbe2c7 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/new-Map2.types @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/es6/mapConstruction/new-Map2.ts] //// + +=== new-Map2.ts === +const m1 = new Map([]); +>m1 : Map +>new Map([]) : Map +>Map : MapConstructor +>[] : never[] + +const a2: any[] = []; +>a2 : any[] +>[] : never[] + +const m2 = new Map(a2); +>m2 : Map +>new Map(a2) : Map +>Map : MapConstructor +>a2 : any[] + +const a3 = []; +>a3 : any[] +>[] : never[] + +const m3 = new Map(a3); +>m3 : Map +>new Map(a3) : Map +>Map : MapConstructor +>a3 : any[] + diff --git a/tsc/testdata/tests/cases/conformance/es6/mapConstruction/new-Map1.ts b/tsc/testdata/tests/cases/conformance/es6/mapConstruction/new-Map1.ts new file mode 100644 index 0000000000000..d97e848cbc0ef --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/es6/mapConstruction/new-Map1.ts @@ -0,0 +1,21 @@ +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-628802102 +const sample: Map = new Map([[1, 1], ["yes", 1]]); + +// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-750412755 +function test(_a: Map) {} +test(new Map([["test" ,true] ,[1 ,false]])) + +// https://github.com/microsoft/TypeScript/issues/33611#issue-498858215 +const M1 = new Map([ + ['k', {a: 1, b: 'asd'}], + ['k', {a: 2, b: 'asd'}], +]); +const M2 = new Map([ + ...M1, + ['k', {a: 1}], +]); + +// Additional cases +const m1 = new Map([['num', 123], ['str', 'val1']]); +const m2 = new Map([['num', 456], ['str', 'val2']] as const); +const m3 = new Map([['num' as const, 456], ['str' as const, 'val2']]); diff --git a/tsc/testdata/tests/cases/conformance/es6/mapConstruction/new-Map2.ts b/tsc/testdata/tests/cases/conformance/es6/mapConstruction/new-Map2.ts new file mode 100644 index 0000000000000..1a07769dd67ce --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/es6/mapConstruction/new-Map2.ts @@ -0,0 +1,7 @@ +const m1 = new Map([]); + +const a2: any[] = []; +const m2 = new Map(a2); + +const a3 = []; +const m3 = new Map(a3);