Skip to content
Open
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
1 change: 1 addition & 0 deletions tsc/internal/bundled/libs/lib.es2015.collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface Map<K, V> {
interface MapConstructor {
new (): Map<any, any>;
new <K, V>(entries?: readonly (readonly [K, V])[] | null): Map<K, V>;
new <KV extends readonly [any, any]>(entries?: readonly KV[] | null): Map<KV[0], KV[1]>;
readonly prototype: Map<any, any>;
}
declare var Map: MapConstructor;
Expand Down
1 change: 1 addition & 0 deletions tsc/internal/bundled/libs/lib.es2015.iterable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ interface ReadonlyMap<K, V> {
interface MapConstructor {
new (): Map<any, any>;
new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
new <KV extends readonly [any, any]>(iterable?: Iterable<KV> | null): Map<KV[0], KV[1]>;
}

interface WeakMap<K extends WeakKey, V> {}
Expand Down
4 changes: 2 additions & 2 deletions tsc/testdata/baselines/reference/compiler/newMap.errors.txt
Original file line number Diff line number Diff line change
@@ -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<string>();
~~~~~~
!!! 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<object>();

16 changes: 0 additions & 16 deletions tsc/testdata/baselines/reference/conformance/for-of39.errors.txt

This file was deleted.

14 changes: 7 additions & 7 deletions tsc/testdata/baselines/reference/conformance/for-of39.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

=== for-of39.ts ===
var map = new Map([["", true], ["", 0]]);
>map : Map<string, number>
>new Map([["", true], ["", 0]]) : Map<string, number>
>map : Map<string, number | boolean>
>new Map([["", true], ["", 0]]) : Map<string, number | boolean>
>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]
Expand All @@ -15,12 +15,12 @@ var map = new Map([["", true], ["", 0]]);

for (var [k, v] of map) {
>k : string
>v : number
>map : Map<string, number>
>v : number | boolean
>map : Map<string, number | boolean>

k;
>k : string

v;
>v : number
>v : number | boolean
}
Original file line number Diff line number Diff line change
@@ -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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! 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'.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>
>...new Map([["", 0], ["hello", true]]) : [string, number | boolean]
>new Map([["", 0], ["hello", true]]) : Map<string, number | boolean>
>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

46 changes: 46 additions & 0 deletions tsc/testdata/baselines/reference/conformance/new-Map1.js
Original file line number Diff line number Diff line change
@@ -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<number | string, number> = new Map([[1, 1], ["yes", 1]]);

// https://github.com/microsoft/TypeScript/issues/37527#issuecomment-750412755
function test(_a: Map<string | number, boolean>) {}
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']]);
61 changes: 61 additions & 0 deletions tsc/testdata/baselines/reference/conformance/new-Map1.symbols
Original file line number Diff line number Diff line change
@@ -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<number | string, number> = 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<string | number, boolean>) {}
>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)

119 changes: 119 additions & 0 deletions tsc/testdata/baselines/reference/conformance/new-Map1.types
Original file line number Diff line number Diff line change
@@ -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<number | string, number> = new Map([[1, 1], ["yes", 1]]);
>sample : Map<string | number, number>
>new Map([[1, 1], ["yes", 1]]) : Map<string | number, number>
>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<string | number, boolean>) {}
>test : (_a: Map<string | number, boolean>) => void
>_a : Map<string | number, boolean>

test(new Map([["test" ,true] ,[1 ,false]]))
>test(new Map([["test" ,true] ,[1 ,false]])) : void
>test : (_a: Map<string | number, boolean>) => void
>new Map([["test" ,true] ,[1 ,false]]) : Map<string | number, boolean>
>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<string, { a: number; b: string; }>
>new Map([ ['k', {a: 1, b: 'asd'}], ['k', {a: 2, b: 'asd'}],]) : Map<string, { a: number; b: string; }>
>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<string, { a: number; b: string; } | { a: number; }>
>new Map([ ...M1, ['k', {a: 1}],]) : Map<string, { a: number; b: string; } | { a: number; }>
>Map : MapConstructor
>[ ...M1, ['k', {a: 1}],] : ([string, { a: number; b: string; }] | [string, { a: number; }])[]

...M1,
>...M1 : [string, { a: number; b: string; }]
>M1 : Map<string, { a: number; b: string; }>

['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<string, string | number>
>new Map([['num', 123], ['str', 'val1']]) : Map<string, string | number>
>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"

17 changes: 17 additions & 0 deletions tsc/testdata/baselines/reference/conformance/new-Map2.errors.txt
Original file line number Diff line number Diff line change
@@ -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.

19 changes: 19 additions & 0 deletions tsc/testdata/baselines/reference/conformance/new-Map2.js
Original file line number Diff line number Diff line change
@@ -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);
Loading