2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts ===
|
|
|
|
// Empty array literal with no contextual type has type Undefined[]
|
|
|
|
|
|
|
|
var arr1= [[], [1], ['']];
|
2014-10-18 01:53:18 +02:00
|
|
|
>arr1 : (string[] | number[])[]
|
|
|
|
>[[], [1], ['']] : (string[] | number[])[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>[] : undefined[]
|
|
|
|
>[1] : number[]
|
|
|
|
>[''] : string[]
|
|
|
|
|
|
|
|
var arr2 = [[null], [1], ['']];
|
2014-10-18 01:53:18 +02:00
|
|
|
>arr2 : (string[] | number[])[]
|
|
|
|
>[[null], [1], ['']] : (string[] | number[])[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>[null] : null[]
|
|
|
|
>[1] : number[]
|
|
|
|
>[''] : string[]
|
|
|
|
|
|
|
|
|
|
|
|
// Array literal with elements of only EveryType E has type E[]
|
|
|
|
var stringArrArr = [[''], [""]];
|
|
|
|
>stringArrArr : string[][]
|
|
|
|
>[[''], [""]] : string[][]
|
|
|
|
>[''] : string[]
|
|
|
|
>[""] : string[]
|
|
|
|
|
|
|
|
var stringArr = ['', ""];
|
|
|
|
>stringArr : string[]
|
|
|
|
>['', ""] : string[]
|
|
|
|
|
|
|
|
var numberArr = [0, 0.0, 0x00, 1e1];
|
|
|
|
>numberArr : number[]
|
|
|
|
>[0, 0.0, 0x00, 1e1] : number[]
|
|
|
|
|
|
|
|
var boolArr = [false, true, false, true];
|
|
|
|
>boolArr : boolean[]
|
|
|
|
>[false, true, false, true] : boolean[]
|
|
|
|
|
|
|
|
class C { private p; }
|
|
|
|
>C : C
|
|
|
|
>p : any
|
|
|
|
|
|
|
|
var classArr = [new C(), new C()];
|
|
|
|
>classArr : C[]
|
|
|
|
>[new C(), new C()] : C[]
|
|
|
|
>new C() : C
|
|
|
|
>C : typeof C
|
|
|
|
>new C() : C
|
|
|
|
>C : typeof C
|
|
|
|
|
|
|
|
var classTypeArray = [C, C, C];
|
|
|
|
>classTypeArray : typeof C[]
|
|
|
|
>[C, C, C] : typeof C[]
|
|
|
|
>C : typeof C
|
|
|
|
>C : typeof C
|
|
|
|
>C : typeof C
|
|
|
|
|
|
|
|
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
|
|
|
|
>classTypeArray : typeof C[]
|
2014-08-19 04:56:03 +02:00
|
|
|
>Array : T[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>C : typeof C
|
|
|
|
|
|
|
|
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
|
|
|
|
var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
|
2014-12-06 01:58:49 +01:00
|
|
|
>context1 : { [n: number]: { a: string; b: number; }; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>n : number
|
|
|
|
>a : string
|
|
|
|
>b : number
|
2014-10-18 01:53:18 +02:00
|
|
|
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
|
|
|
|
>a : string
|
|
|
|
>b : number
|
|
|
|
>c : string
|
|
|
|
>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
|
|
|
|
>a : string
|
|
|
|
>b : number
|
|
|
|
>c : number
|
|
|
|
|
|
|
|
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
|
2014-10-18 01:53:18 +02:00
|
|
|
>context2 : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
|
|
|
|
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
|
|
|
|
>a : string
|
|
|
|
>b : number
|
|
|
|
>c : string
|
|
|
|
>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
|
|
|
|
>a : string
|
|
|
|
>b : number
|
|
|
|
>c : number
|
|
|
|
|
|
|
|
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
|
|
|
|
class Base { private p; }
|
|
|
|
>Base : Base
|
|
|
|
>p : any
|
|
|
|
|
|
|
|
class Derived1 extends Base { private m };
|
|
|
|
>Derived1 : Derived1
|
|
|
|
>Base : Base
|
|
|
|
>m : any
|
|
|
|
|
|
|
|
class Derived2 extends Base { private n };
|
|
|
|
>Derived2 : Derived2
|
|
|
|
>Base : Base
|
|
|
|
>n : any
|
|
|
|
|
|
|
|
var context3: Base[] = [new Derived1(), new Derived2()];
|
|
|
|
>context3 : Base[]
|
|
|
|
>Base : Base
|
2014-10-18 01:53:18 +02:00
|
|
|
>[new Derived1(), new Derived2()] : (Derived1 | Derived2)[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>new Derived1() : Derived1
|
|
|
|
>Derived1 : typeof Derived1
|
|
|
|
>new Derived2() : Derived2
|
|
|
|
>Derived2 : typeof Derived2
|
|
|
|
|
|
|
|
// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
|
|
|
|
var context4: Base[] = [new Derived1(), new Derived1()];
|
|
|
|
>context4 : Base[]
|
|
|
|
>Base : Base
|
2014-10-13 15:56:58 +02:00
|
|
|
>[new Derived1(), new Derived1()] : Derived1[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>new Derived1() : Derived1
|
|
|
|
>Derived1 : typeof Derived1
|
|
|
|
>new Derived1() : Derived1
|
|
|
|
>Derived1 : typeof Derived1
|
|
|
|
|
|
|
|
|