Skip to content

Commit fd5b808

Browse files
committed
Accepting new baselines
The new baselines all look correct to me, but obviously a number of the tests need to be updated to reflect union types and the new behavior of best common type. This commit does not cover that.
1 parent 95584e9 commit fd5b808

File tree

93 files changed

+1293
-2754
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1293
-2754
lines changed

tests/baselines/reference/arrayBestCommonTypes.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -294,22 +294,22 @@ class f {
294294
>base2 : typeof base2
295295

296296
var b1 = [ baseObj, base2Obj, ifaceObj ];
297-
>b1 : base[]
298-
>[ baseObj, base2Obj, ifaceObj ] : base[]
297+
>b1 : iface[]
298+
>[ baseObj, base2Obj, ifaceObj ] : iface[]
299299
>baseObj : base
300300
>base2Obj : base2
301301
>ifaceObj : iface
302302

303303
var b2 = [ base2Obj, baseObj, ifaceObj ];
304-
>b2 : base2[]
305-
>[ base2Obj, baseObj, ifaceObj ] : base2[]
304+
>b2 : iface[]
305+
>[ base2Obj, baseObj, ifaceObj ] : iface[]
306306
>base2Obj : base2
307307
>baseObj : base
308308
>ifaceObj : iface
309309

310310
var b3 = [ baseObj, ifaceObj, base2Obj ];
311-
>b3 : base[]
312-
>[ baseObj, ifaceObj, base2Obj ] : base[]
311+
>b3 : iface[]
312+
>[ baseObj, ifaceObj, base2Obj ] : iface[]
313313
>baseObj : base
314314
>ifaceObj : iface
315315
>base2Obj : base2

tests/baselines/reference/arrayLiteralContextualType.errors.txt

-40
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
=== tests/cases/compiler/arrayLiteralContextualType.ts ===
2+
interface IAnimal {
3+
>IAnimal : IAnimal
4+
5+
name: string;
6+
>name : string
7+
}
8+
9+
class Giraffe {
10+
>Giraffe : Giraffe
11+
12+
name = "Giraffe";
13+
>name : string
14+
15+
neckLength = "3m";
16+
>neckLength : string
17+
}
18+
19+
class Elephant {
20+
>Elephant : Elephant
21+
22+
name = "Elephant";
23+
>name : string
24+
25+
trunkDiameter = "20cm";
26+
>trunkDiameter : string
27+
}
28+
29+
function foo(animals: IAnimal[]) { }
30+
>foo : (animals: IAnimal[]) => void
31+
>animals : IAnimal[]
32+
>IAnimal : IAnimal
33+
34+
function bar(animals: { [n: number]: IAnimal }) { }
35+
>bar : (animals: { [x: number]: IAnimal; }) => void
36+
>animals : { [x: number]: IAnimal; }
37+
>n : number
38+
>IAnimal : IAnimal
39+
40+
foo([
41+
>foo([ new Giraffe(), new Elephant()]) : void
42+
>foo : (animals: IAnimal[]) => void
43+
>[ new Giraffe(), new Elephant()] : IAnimal[]
44+
45+
new Giraffe(),
46+
>new Giraffe() : Giraffe
47+
>Giraffe : typeof Giraffe
48+
49+
new Elephant()
50+
>new Elephant() : Elephant
51+
>Elephant : typeof Elephant
52+
53+
]); // Legal because of the contextual type IAnimal provided by the parameter
54+
bar([
55+
>bar([ new Giraffe(), new Elephant()]) : void
56+
>bar : (animals: { [x: number]: IAnimal; }) => void
57+
>[ new Giraffe(), new Elephant()] : IAnimal[]
58+
59+
new Giraffe(),
60+
>new Giraffe() : Giraffe
61+
>Giraffe : typeof Giraffe
62+
63+
new Elephant()
64+
>new Elephant() : Elephant
65+
>Elephant : typeof Elephant
66+
67+
]); // Legal because of the contextual type IAnimal provided by the parameter
68+
69+
var arr = [new Giraffe(), new Elephant()];
70+
>arr : Array<Giraffe | Elephant>
71+
>[new Giraffe(), new Elephant()] : Array<Giraffe | Elephant>
72+
>new Giraffe() : Giraffe
73+
>Giraffe : typeof Giraffe
74+
>new Elephant() : Elephant
75+
>Elephant : typeof Elephant
76+
77+
foo(arr); // Error because of no contextual type
78+
>foo(arr) : void
79+
>foo : (animals: IAnimal[]) => void
80+
>arr : Array<Giraffe | Elephant>
81+
82+
bar(arr); // Error because of no contextual type
83+
>bar(arr) : void
84+
>bar : (animals: { [x: number]: IAnimal; }) => void
85+
>arr : Array<Giraffe | Elephant>
86+

tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var as = [a, b]; // { x: number; y?: number };[]
2323
>b : { x: number; z?: number; }
2424

2525
var bs = [b, a]; // { x: number; z?: number };[]
26-
>bs : { x: number; z?: number; }[]
27-
>[b, a] : { x: number; z?: number; }[]
26+
>bs : { x: number; y?: number; }[]
27+
>[b, a] : { x: number; y?: number; }[]
2828
>b : { x: number; z?: number; }
2929
>a : { x: number; y?: number; }
3030

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(4,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr1' must be of type 'Array<string[] | number[]>', but here has type '{}[]'.
2+
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(7,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'Array<string[] | number[]>', but here has type '{}[]'.
3+
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(33,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'context2' must be of type 'Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>', but here has type '{}[]'.
4+
5+
6+
==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts (3 errors) ====
7+
// Empty array literal with no contextual type has type Undefined[]
8+
9+
var arr1= [[], [1], ['']];
10+
var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
11+
~~~~
12+
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr1' must be of type 'Array<string[] | number[]>', but here has type '{}[]'.
13+
14+
var arr2 = [[null], [1], ['']];
15+
var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
16+
~~~~
17+
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'Array<string[] | number[]>', but here has type '{}[]'.
18+
19+
20+
// Array literal with elements of only EveryType E has type E[]
21+
var stringArrArr = [[''], [""]];
22+
var stringArrArr: string[][];
23+
24+
var stringArr = ['', ""];
25+
var stringArr: string[];
26+
27+
var numberArr = [0, 0.0, 0x00, 1e1];
28+
var numberArr: number[];
29+
30+
var boolArr = [false, true, false, true];
31+
var boolArr: boolean[];
32+
33+
class C { private p; }
34+
var classArr = [new C(), new C()];
35+
var classArr: C[]; // Should be OK
36+
37+
var classTypeArray = [C, C, C];
38+
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
39+
40+
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
41+
var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
42+
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
43+
var context2: Array<{}>; // Should be OK
44+
~~~~~~~~
45+
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'context2' must be of type 'Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>', but here has type '{}[]'.
46+
47+
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
48+
class Base { private p; }
49+
class Derived1 extends Base { private m };
50+
class Derived2 extends Base { private n };
51+
var context3: Base[] = [new Derived1(), new Derived2()];
52+
53+
// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
54+
var context4: Base[] = [new Derived1(), new Derived1()];
55+
56+

tests/baselines/reference/arrayLiterals.types

-150
This file was deleted.

tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ var xs = [list, myList]; // {}[]
6161
>myList : MyList<number>
6262

6363
var ys = [list, list2]; // {}[]
64-
>ys : {}[]
65-
>[list, list2] : {}[]
64+
>ys : Array<List<number> | List<string>>
65+
>[list, list2] : Array<List<number> | List<string>>
6666
>list : List<number>
6767
>list2 : List<string>
6868

tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ var r4 = true ? a : b; // typeof a
5454
>b : { x: number; z?: number; }
5555

5656
var r5 = true ? b : a; // typeof b
57-
>r5 : { x: number; z?: number; }
58-
>true ? b : a : { x: number; z?: number; }
57+
>r5 : { x: number; y?: number; }
58+
>true ? b : a : { x: number; y?: number; }
5959
>b : { x: number; z?: number; }
6060
>a : { x: number; y?: number; }
6161

0 commit comments

Comments
 (0)