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], ['']];
|
2015-04-13 23:01:57 +02:00
|
|
|
>arr1 : (string[] | number[])[], Symbol(arr1, Decl(arrayLiterals.ts, 2, 3))
|
2014-10-18 01:53:18 +02:00
|
|
|
>[[], [1], ['']] : (string[] | number[])[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>[] : undefined[]
|
|
|
|
>[1] : number[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>1 : number
|
2014-08-15 23:33:16 +02:00
|
|
|
>[''] : string[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var arr2 = [[null], [1], ['']];
|
2015-04-13 23:01:57 +02:00
|
|
|
>arr2 : (string[] | number[])[], Symbol(arr2, Decl(arrayLiterals.ts, 4, 3))
|
2014-10-18 01:53:18 +02:00
|
|
|
>[[null], [1], ['']] : (string[] | number[])[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>[null] : null[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>null : null
|
2014-08-15 23:33:16 +02:00
|
|
|
>[1] : number[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>1 : number
|
2014-08-15 23:33:16 +02:00
|
|
|
>[''] : string[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Array literal with elements of only EveryType E has type E[]
|
|
|
|
var stringArrArr = [[''], [""]];
|
2015-04-13 23:01:57 +02:00
|
|
|
>stringArrArr : string[][], Symbol(stringArrArr, Decl(arrayLiterals.ts, 8, 3))
|
2014-08-15 23:33:16 +02:00
|
|
|
>[[''], [""]] : string[][]
|
|
|
|
>[''] : string[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
2014-08-15 23:33:16 +02:00
|
|
|
>[""] : string[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>"" : string
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var stringArr = ['', ""];
|
2015-04-13 23:01:57 +02:00
|
|
|
>stringArr : string[], Symbol(stringArr, Decl(arrayLiterals.ts, 10, 3))
|
2014-08-15 23:33:16 +02:00
|
|
|
>['', ""] : string[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
|
|
|
>"" : string
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var numberArr = [0, 0.0, 0x00, 1e1];
|
2015-04-13 23:01:57 +02:00
|
|
|
>numberArr : number[], Symbol(numberArr, Decl(arrayLiterals.ts, 12, 3))
|
2014-08-15 23:33:16 +02:00
|
|
|
>[0, 0.0, 0x00, 1e1] : number[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>0 : number
|
|
|
|
>0.0 : number
|
|
|
|
>0x00 : number
|
|
|
|
>1e1 : number
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var boolArr = [false, true, false, true];
|
2015-04-13 23:01:57 +02:00
|
|
|
>boolArr : boolean[], Symbol(boolArr, Decl(arrayLiterals.ts, 14, 3))
|
2014-08-15 23:33:16 +02:00
|
|
|
>[false, true, false, true] : boolean[]
|
2015-04-13 21:36:11 +02:00
|
|
|
>false : boolean
|
|
|
|
>true : boolean
|
|
|
|
>false : boolean
|
|
|
|
>true : boolean
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
class C { private p; }
|
2015-04-13 23:01:57 +02:00
|
|
|
>C : C, Symbol(C, Decl(arrayLiterals.ts, 14, 41))
|
|
|
|
>p : any, Symbol(p, Decl(arrayLiterals.ts, 16, 9))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var classArr = [new C(), new C()];
|
2015-04-13 23:01:57 +02:00
|
|
|
>classArr : C[], Symbol(classArr, Decl(arrayLiterals.ts, 17, 3))
|
2014-08-15 23:33:16 +02:00
|
|
|
>[new C(), new C()] : C[]
|
|
|
|
>new C() : C
|
2015-04-13 23:01:57 +02:00
|
|
|
>C : typeof C, Symbol(C, Decl(arrayLiterals.ts, 14, 41))
|
2014-08-15 23:33:16 +02:00
|
|
|
>new C() : C
|
2015-04-13 23:01:57 +02:00
|
|
|
>C : typeof C, Symbol(C, Decl(arrayLiterals.ts, 14, 41))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var classTypeArray = [C, C, C];
|
2015-04-13 23:01:57 +02:00
|
|
|
>classTypeArray : typeof C[], Symbol(classTypeArray, Decl(arrayLiterals.ts, 19, 3), Decl(arrayLiterals.ts, 20, 3))
|
2014-08-15 23:33:16 +02:00
|
|
|
>[C, C, C] : typeof C[]
|
2015-04-13 23:01:57 +02:00
|
|
|
>C : typeof C, Symbol(C, Decl(arrayLiterals.ts, 14, 41))
|
|
|
|
>C : typeof C, Symbol(C, Decl(arrayLiterals.ts, 14, 41))
|
|
|
|
>C : typeof C, Symbol(C, Decl(arrayLiterals.ts, 14, 41))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
|
2015-04-13 23:01:57 +02:00
|
|
|
>classTypeArray : typeof C[], Symbol(classTypeArray, Decl(arrayLiterals.ts, 19, 3), Decl(arrayLiterals.ts, 20, 3))
|
|
|
|
>Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
|
|
|
|
>C : typeof C, Symbol(C, Decl(arrayLiterals.ts, 14, 41))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
// 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 }];
|
2015-04-13 23:01:57 +02:00
|
|
|
>context1 : { [n: number]: { a: string; b: number; }; }, Symbol(context1, Decl(arrayLiterals.ts, 23, 3))
|
|
|
|
>n : number, Symbol(n, Decl(arrayLiterals.ts, 23, 17))
|
|
|
|
>a : string, Symbol(a, Decl(arrayLiterals.ts, 23, 30))
|
|
|
|
>b : number, Symbol(b, Decl(arrayLiterals.ts, 23, 41))
|
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; }
|
2015-04-13 23:01:57 +02:00
|
|
|
>a : string, Symbol(a, Decl(arrayLiterals.ts, 23, 62))
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>b : number, Symbol(b, Decl(arrayLiterals.ts, 23, 69))
|
2015-04-13 21:36:11 +02:00
|
|
|
>0 : number
|
2015-04-13 23:01:57 +02:00
|
|
|
>c : string, Symbol(c, Decl(arrayLiterals.ts, 23, 75))
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
2014-08-15 23:33:16 +02:00
|
|
|
>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
|
2015-04-13 23:01:57 +02:00
|
|
|
>a : string, Symbol(a, Decl(arrayLiterals.ts, 23, 86))
|
2015-04-13 21:36:11 +02:00
|
|
|
>"" : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>b : number, Symbol(b, Decl(arrayLiterals.ts, 23, 93))
|
2015-04-13 21:36:11 +02:00
|
|
|
>3 : number
|
2015-04-13 23:01:57 +02:00
|
|
|
>c : number, Symbol(c, Decl(arrayLiterals.ts, 23, 99))
|
2015-04-13 21:36:11 +02:00
|
|
|
>0 : number
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
|
2015-04-13 23:01:57 +02:00
|
|
|
>context2 : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[], Symbol(context2, Decl(arrayLiterals.ts, 24, 3))
|
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; }
|
2015-04-13 23:01:57 +02:00
|
|
|
>a : string, Symbol(a, Decl(arrayLiterals.ts, 24, 17))
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>b : number, Symbol(b, Decl(arrayLiterals.ts, 24, 24))
|
2015-04-13 21:36:11 +02:00
|
|
|
>0 : number
|
2015-04-13 23:01:57 +02:00
|
|
|
>c : string, Symbol(c, Decl(arrayLiterals.ts, 24, 30))
|
2015-04-13 21:36:11 +02:00
|
|
|
>'' : string
|
2014-08-15 23:33:16 +02:00
|
|
|
>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
|
2015-04-13 23:01:57 +02:00
|
|
|
>a : string, Symbol(a, Decl(arrayLiterals.ts, 24, 41))
|
2015-04-13 21:36:11 +02:00
|
|
|
>"" : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>b : number, Symbol(b, Decl(arrayLiterals.ts, 24, 48))
|
2015-04-13 21:36:11 +02:00
|
|
|
>3 : number
|
2015-04-13 23:01:57 +02:00
|
|
|
>c : number, Symbol(c, Decl(arrayLiterals.ts, 24, 54))
|
2015-04-13 21:36:11 +02:00
|
|
|
>0 : number
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
|
|
|
|
class Base { private p; }
|
2015-04-13 23:01:57 +02:00
|
|
|
>Base : Base, Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
|
|
|
|
>p : any, Symbol(p, Decl(arrayLiterals.ts, 27, 12))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
class Derived1 extends Base { private m };
|
2015-04-13 23:01:57 +02:00
|
|
|
>Derived1 : Derived1, Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))
|
|
|
|
>Base : Base, Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
|
|
|
|
>m : any, Symbol(m, Decl(arrayLiterals.ts, 28, 29))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
class Derived2 extends Base { private n };
|
2015-04-13 23:01:57 +02:00
|
|
|
>Derived2 : Derived2, Symbol(Derived2, Decl(arrayLiterals.ts, 28, 42))
|
|
|
|
>Base : Base, Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
|
|
|
|
>n : any, Symbol(n, Decl(arrayLiterals.ts, 29, 29))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var context3: Base[] = [new Derived1(), new Derived2()];
|
2015-04-13 23:01:57 +02:00
|
|
|
>context3 : Base[], Symbol(context3, Decl(arrayLiterals.ts, 30, 3))
|
|
|
|
>Base : Base, Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
|
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
|
2015-04-13 23:01:57 +02:00
|
|
|
>Derived1 : typeof Derived1, Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))
|
2014-08-15 23:33:16 +02:00
|
|
|
>new Derived2() : Derived2
|
2015-04-13 23:01:57 +02:00
|
|
|
>Derived2 : typeof Derived2, Symbol(Derived2, Decl(arrayLiterals.ts, 28, 42))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
// 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()];
|
2015-04-13 23:01:57 +02:00
|
|
|
>context4 : Base[], Symbol(context4, Decl(arrayLiterals.ts, 33, 3))
|
|
|
|
>Base : Base, Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
|
2014-10-13 15:56:58 +02:00
|
|
|
>[new Derived1(), new Derived1()] : Derived1[]
|
2014-08-15 23:33:16 +02:00
|
|
|
>new Derived1() : Derived1
|
2015-04-13 23:01:57 +02:00
|
|
|
>Derived1 : typeof Derived1, Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))
|
2014-08-15 23:33:16 +02:00
|
|
|
>new Derived1() : Derived1
|
2015-04-13 23:01:57 +02:00
|
|
|
>Derived1 : typeof Derived1, Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
|