=== tests/cases/conformance/types/union/unionTypeFromArrayLiteral.ts === // The resulting type an array literal expression is determined as follows: // If the array literal is empty, the resulting type is an array type with the element type Undefined. // Otherwise, if the array literal is contextually typed by a type that has a property with the numeric name ‘0’, the resulting type is a tuple type constructed from the types of the element expressions. // Otherwise, the resulting type is an array type with an element type that is the union of the types of the element expressions. var arr1 = [1, 2]; // number[] >arr1 : number[] >[1, 2] : number[] >1 : number >2 : number var arr2 = ["hello", true]; // (string | number)[] >arr2 : (string | boolean)[] >["hello", true] : (string | boolean)[] >"hello" : string >true : boolean var arr3Tuple: [number, string] = [3, "three"]; // [number, string] >arr3Tuple : [number, string] >[3, "three"] : [number, string] >3 : number >"three" : string var arr4Tuple: [number, string] = [3, "three", "hello"]; // [number, string, string] >arr4Tuple : [number, string] >[3, "three", "hello"] : [number, string, string] >3 : number >"three" : string >"hello" : string var arrEmpty = []; >arrEmpty : any[] >[] : undefined[] var arr5Tuple: { >arr5Tuple : { 0: string; 5: number; } 0: string; 5: number; } = ["hello", true, false, " hello", true, 10, "any"]; // Tuple >["hello", true, false, " hello", true, 10, "any"] : [string, boolean, boolean, string, boolean, number, string] >"hello" : string >true : boolean >false : boolean >" hello" : string >true : boolean >10 : number >"any" : string class C { foo() { } } >C : C >foo : () => void class D { foo2() { } } >D : D >foo2 : () => void class E extends C { foo3() { } } >E : E >C : C >foo3 : () => void class F extends C { foo4() { } } >F : F >C : C >foo4 : () => void var c: C, d: D, e: E, f: F; >c : C >C : C >d : D >D : D >e : E >E : E >f : F >F : F var arr6 = [c, d]; // (C | D)[] >arr6 : (C | D)[] >[c, d] : (C | D)[] >c : C >d : D var arr7 = [c, d, e]; // (C | D)[] >arr7 : (C | D)[] >[c, d, e] : (C | D)[] >c : C >d : D >e : E var arr8 = [c, e]; // C[] >arr8 : C[] >[c, e] : C[] >c : C >e : E var arr9 = [e, f]; // (E|F)[] >arr9 : (E | F)[] >[e, f] : (E | F)[] >e : E >f : F