Merge pull request #2753 from Microsoft/conformanceArrayLiteral

Conformance test for update in section 4.6 Array Literal
This commit is contained in:
Yui
2015-05-04 10:50:41 -07:00
11 changed files with 1192 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
//// [arrayLiterals2ES5.ts]
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [,, 2, 3, 4]
var a1 = ["hello", "world"]
var a2 = [, , , ...a0, "hello"];
var a3 = [,, ...a0]
var a4 = [() => 1, ];
var a5 = [...a0, , ]
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
var temp3 = [undefined, null, undefined];
var temp4 = [];
interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
var d1 = [...temp]; // has type string[]
var d2: number[] = [...temp1];
var d3: myArray = [...temp1];
var d4: myArray2 = [...temp, ...temp1];
var d5 = [...temp3];
var d6 = [...temp4];
var d7 = [...[...temp1]];
var d8: number[][] = [[...temp1]]
var d9 = [[...temp1], ...["hello"]];
//// [arrayLiterals2ES5.js]
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4];
var a1 = ["hello", "world"];
var a2 = [, , ].concat(a0, ["hello"]);
var a3 = [, ].concat(a0);
var a4 = [function () { return 1; },];
var a5 = a0.concat([,]);
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0 = [undefined, null, undefined];
var b1 = [[1, 2, 3], ["hello", "string"]];
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var _a = [1, 2], c0 = _a[0], c1 = _a[1]; // tuple type [number, number]
var _b = [1, 2, true], c2 = _b[0], c3 = _b[1]; // tuple type [number, number, boolean]
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2 = [[1, 2, 3], ["hello", "string"]];
var temp3 = [undefined, null, undefined];
var temp4 = [];
var d0 = [1, true].concat(temp); // has type (string|number|boolean)[]
var d1 = temp; // has type string[]
var d2 = temp1;
var d3 = temp1;
var d4 = temp.concat(temp1);
var d5 = temp3;
var d6 = temp4;
var d7 = temp1;
var d8 = [temp1];
var d9 = [temp1].concat(["hello"]);

View File

@@ -0,0 +1,134 @@
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts ===
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [,, 2, 3, 4]
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
var a1 = ["hello", "world"]
>a1 : Symbol(a1, Decl(arrayLiterals2ES5.ts, 10, 3))
var a2 = [, , , ...a0, "hello"];
>a2 : Symbol(a2, Decl(arrayLiterals2ES5.ts, 11, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
var a3 = [,, ...a0]
>a3 : Symbol(a3, Decl(arrayLiterals2ES5.ts, 12, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
var a4 = [() => 1, ];
>a4 : Symbol(a4, Decl(arrayLiterals2ES5.ts, 13, 3))
var a5 = [...a0, , ]
>a5 : Symbol(a5, Decl(arrayLiterals2ES5.ts, 14, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3))
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
>b0 : Symbol(b0, Decl(arrayLiterals2ES5.ts, 25, 3))
>undefined : Symbol(undefined)
>undefined : Symbol(undefined)
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>b1 : Symbol(b1, Decl(arrayLiterals2ES5.ts, 26, 3))
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
>c0 : Symbol(c0, Decl(arrayLiterals2ES5.ts, 32, 5))
>c1 : Symbol(c1, Decl(arrayLiterals2ES5.ts, 32, 8))
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
>c2 : Symbol(c2, Decl(arrayLiterals2ES5.ts, 33, 5))
>c3 : Symbol(c3, Decl(arrayLiterals2ES5.ts, 33, 8))
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
var temp1 = [1, 2, 3];
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>temp2 : Symbol(temp2, Decl(arrayLiterals2ES5.ts, 40, 3))
var temp3 = [undefined, null, undefined];
>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3))
>undefined : Symbol(undefined)
>undefined : Symbol(undefined)
var temp4 = [];
>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3))
interface myArray extends Array<Number> { }
>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15))
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
interface myArray2 extends Array<Number|String> { }
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43))
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11))
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
>d0 : Symbol(d0, Decl(arrayLiterals2ES5.ts, 46, 3))
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
var d1 = [...temp]; // has type string[]
>d1 : Symbol(d1, Decl(arrayLiterals2ES5.ts, 47, 3))
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
var d2: number[] = [...temp1];
>d2 : Symbol(d2, Decl(arrayLiterals2ES5.ts, 48, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
var d3: myArray = [...temp1];
>d3 : Symbol(d3, Decl(arrayLiterals2ES5.ts, 49, 3))
>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
var d4: myArray2 = [...temp, ...temp1];
>d4 : Symbol(d4, Decl(arrayLiterals2ES5.ts, 50, 3))
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43))
>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
var d5 = [...temp3];
>d5 : Symbol(d5, Decl(arrayLiterals2ES5.ts, 51, 3))
>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3))
var d6 = [...temp4];
>d6 : Symbol(d6, Decl(arrayLiterals2ES5.ts, 52, 3))
>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3))
var d7 = [...[...temp1]];
>d7 : Symbol(d7, Decl(arrayLiterals2ES5.ts, 53, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
var d8: number[][] = [[...temp1]]
>d8 : Symbol(d8, Decl(arrayLiterals2ES5.ts, 54, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))
var d9 = [[...temp1], ...["hello"]];
>d9 : Symbol(d9, Decl(arrayLiterals2ES5.ts, 55, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3))

View File

@@ -0,0 +1,225 @@
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts ===
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [,, 2, 3, 4]
>a0 : number[]
>[,, 2, 3, 4] : number[]
> : undefined
> : undefined
>2 : number
>3 : number
>4 : number
var a1 = ["hello", "world"]
>a1 : string[]
>["hello", "world"] : string[]
>"hello" : string
>"world" : string
var a2 = [, , , ...a0, "hello"];
>a2 : (string | number)[]
>[, , , ...a0, "hello"] : (string | number)[]
> : undefined
> : undefined
> : undefined
>...a0 : number
>a0 : number[]
>"hello" : string
var a3 = [,, ...a0]
>a3 : number[]
>[,, ...a0] : number[]
> : undefined
> : undefined
>...a0 : number
>a0 : number[]
var a4 = [() => 1, ];
>a4 : (() => number)[]
>[() => 1, ] : (() => number)[]
>() => 1 : () => number
>1 : number
var a5 = [...a0, , ]
>a5 : number[]
>[...a0, , ] : number[]
>...a0 : number
>a0 : number[]
> : undefined
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
>b0 : [any, any, any]
>[undefined, null, undefined] : [undefined, null, undefined]
>undefined : undefined
>null : null
>undefined : undefined
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>b1 : [number[], string[]]
>[[1, 2, 3], ["hello", "string"]] : [number[], string[]]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
>["hello", "string"] : string[]
>"hello" : string
>"string" : string
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
>c0 : number
>c1 : number
>[1, 2] : [number, number]
>1 : number
>2 : number
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
>c2 : number
>c3 : number
>[1, 2, true] : [number, number, boolean]
>1 : number
>2 : number
>true : boolean
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
>temp : string[]
>["s", "t", "r"] : string[]
>"s" : string
>"t" : string
>"r" : string
var temp1 = [1, 2, 3];
>temp1 : number[]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>temp2 : [number[], string[]]
>[[1, 2, 3], ["hello", "string"]] : [number[], string[]]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
>["hello", "string"] : string[]
>"hello" : string
>"string" : string
var temp3 = [undefined, null, undefined];
>temp3 : any[]
>[undefined, null, undefined] : null[]
>undefined : undefined
>null : null
>undefined : undefined
var temp4 = [];
>temp4 : any[]
>[] : undefined[]
interface myArray extends Array<Number> { }
>myArray : myArray
>Array : T[]
>Number : Number
interface myArray2 extends Array<Number|String> { }
>myArray2 : myArray2
>Array : T[]
>Number : Number
>String : String
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
>d0 : (string | number | boolean)[]
>[1, true, ...temp,] : (string | number | boolean)[]
>1 : number
>true : boolean
>...temp : string
>temp : string[]
var d1 = [...temp]; // has type string[]
>d1 : string[]
>[...temp] : string[]
>...temp : string
>temp : string[]
var d2: number[] = [...temp1];
>d2 : number[]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
var d3: myArray = [...temp1];
>d3 : myArray
>myArray : myArray
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
var d4: myArray2 = [...temp, ...temp1];
>d4 : myArray2
>myArray2 : myArray2
>[...temp, ...temp1] : (string | number)[]
>...temp : string
>temp : string[]
>...temp1 : number
>temp1 : number[]
var d5 = [...temp3];
>d5 : any[]
>[...temp3] : any[]
>...temp3 : any
>temp3 : any[]
var d6 = [...temp4];
>d6 : any[]
>[...temp4] : any[]
>...temp4 : any
>temp4 : any[]
var d7 = [...[...temp1]];
>d7 : number[]
>[...[...temp1]] : number[]
>...[...temp1] : number
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
var d8: number[][] = [[...temp1]]
>d8 : number[][]
>[[...temp1]] : number[][]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
var d9 = [[...temp1], ...["hello"]];
>d9 : (string | number[])[]
>[[...temp1], ...["hello"]] : (string | number[])[]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
>...["hello"] : string
>["hello"] : string[]
>"hello" : string

View File

@@ -0,0 +1,100 @@
//// [arrayLiterals2ES6.ts]
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4]
var a1 = ["hello", "world"]
var a2 = [, , , ...a0, "hello"];
var a3 = [, , ...a0]
var a4 = [() => 1, ];
var a5 = [...a0, , ]
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[]
var d1 = [...temp]; // has type string[]
var d2: number[] = [...temp1];
var d3: myArray = [...temp1];
var d4: myArray2 = [...temp, ...temp1];
var d5 = [...a2];
var d6 = [...a3];
var d7 = [...a4];
var d8: number[][] = [[...temp1]]
var d9 = [[...temp1], ...["hello"]];
//// [arrayLiterals2ES6.js]
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4];
var a1 = ["hello", "world"];
var a2 = [, , , ...a0, "hello"];
var a3 = [, , ...a0];
var a4 = [() => 1,];
var a5 = [...a0, ,];
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0 = [undefined, null, undefined];
var b1 = [[1, 2, 3], ["hello", "string"]];
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2 = [[1, 2, 3], ["hello", "string"]];
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
var d1 = [...temp]; // has type string[]
var d2 = [...temp1];
var d3 = [...temp1];
var d4 = [...temp, ...temp1];
var d5 = [...a2];
var d6 = [...a3];
var d7 = [...a4];
var d8 = [[...temp1]];
var d9 = [[...temp1], ...["hello"]];

View File

@@ -0,0 +1,126 @@
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts ===
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4]
>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3))
var a1 = ["hello", "world"]
>a1 : Symbol(a1, Decl(arrayLiterals2ES6.ts, 10, 3))
var a2 = [, , , ...a0, "hello"];
>a2 : Symbol(a2, Decl(arrayLiterals2ES6.ts, 11, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3))
var a3 = [, , ...a0]
>a3 : Symbol(a3, Decl(arrayLiterals2ES6.ts, 12, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3))
var a4 = [() => 1, ];
>a4 : Symbol(a4, Decl(arrayLiterals2ES6.ts, 13, 3))
var a5 = [...a0, , ]
>a5 : Symbol(a5, Decl(arrayLiterals2ES6.ts, 14, 3))
>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3))
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
>b0 : Symbol(b0, Decl(arrayLiterals2ES6.ts, 25, 3))
>undefined : Symbol(undefined)
>undefined : Symbol(undefined)
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>b1 : Symbol(b1, Decl(arrayLiterals2ES6.ts, 26, 3))
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
>c0 : Symbol(c0, Decl(arrayLiterals2ES6.ts, 32, 5))
>c1 : Symbol(c1, Decl(arrayLiterals2ES6.ts, 32, 8))
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
>c2 : Symbol(c2, Decl(arrayLiterals2ES6.ts, 33, 5))
>c3 : Symbol(c3, Decl(arrayLiterals2ES6.ts, 33, 8))
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3))
var temp1 = [1, 2, 3];
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3))
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>temp2 : Symbol(temp2, Decl(arrayLiterals2ES6.ts, 40, 3))
interface myArray extends Array<Number> { }
>myArray : Symbol(myArray, Decl(arrayLiterals2ES6.ts, 40, 67))
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1))
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
interface myArray2 extends Array<Number|String> { }
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES6.ts, 42, 43))
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1))
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1))
var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[]
>d0 : Symbol(d0, Decl(arrayLiterals2ES6.ts, 44, 3))
>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3))
var d1 = [...temp]; // has type string[]
>d1 : Symbol(d1, Decl(arrayLiterals2ES6.ts, 45, 3))
>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3))
var d2: number[] = [...temp1];
>d2 : Symbol(d2, Decl(arrayLiterals2ES6.ts, 46, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3))
var d3: myArray = [...temp1];
>d3 : Symbol(d3, Decl(arrayLiterals2ES6.ts, 47, 3))
>myArray : Symbol(myArray, Decl(arrayLiterals2ES6.ts, 40, 67))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3))
var d4: myArray2 = [...temp, ...temp1];
>d4 : Symbol(d4, Decl(arrayLiterals2ES6.ts, 48, 3))
>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES6.ts, 42, 43))
>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3))
var d5 = [...a2];
>d5 : Symbol(d5, Decl(arrayLiterals2ES6.ts, 49, 3))
>a2 : Symbol(a2, Decl(arrayLiterals2ES6.ts, 11, 3))
var d6 = [...a3];
>d6 : Symbol(d6, Decl(arrayLiterals2ES6.ts, 50, 3))
>a3 : Symbol(a3, Decl(arrayLiterals2ES6.ts, 12, 3))
var d7 = [...a4];
>d7 : Symbol(d7, Decl(arrayLiterals2ES6.ts, 51, 3))
>a4 : Symbol(a4, Decl(arrayLiterals2ES6.ts, 13, 3))
var d8: number[][] = [[...temp1]]
>d8 : Symbol(d8, Decl(arrayLiterals2ES6.ts, 52, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3))
var d9 = [[...temp1], ...["hello"]];
>d9 : Symbol(d9, Decl(arrayLiterals2ES6.ts, 53, 3))
>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3))

View File

@@ -0,0 +1,212 @@
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts ===
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4]
>a0 : number[]
>[, , 2, 3, 4] : number[]
> : undefined
> : undefined
>2 : number
>3 : number
>4 : number
var a1 = ["hello", "world"]
>a1 : string[]
>["hello", "world"] : string[]
>"hello" : string
>"world" : string
var a2 = [, , , ...a0, "hello"];
>a2 : (string | number)[]
>[, , , ...a0, "hello"] : (string | number)[]
> : undefined
> : undefined
> : undefined
>...a0 : number
>a0 : number[]
>"hello" : string
var a3 = [, , ...a0]
>a3 : number[]
>[, , ...a0] : number[]
> : undefined
> : undefined
>...a0 : number
>a0 : number[]
var a4 = [() => 1, ];
>a4 : (() => number)[]
>[() => 1, ] : (() => number)[]
>() => 1 : () => number
>1 : number
var a5 = [...a0, , ]
>a5 : number[]
>[...a0, , ] : number[]
>...a0 : number
>a0 : number[]
> : undefined
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
>b0 : [any, any, any]
>[undefined, null, undefined] : [undefined, null, undefined]
>undefined : undefined
>null : null
>undefined : undefined
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>b1 : [number[], string[]]
>[[1, 2, 3], ["hello", "string"]] : [number[], string[]]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
>["hello", "string"] : string[]
>"hello" : string
>"string" : string
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
>c0 : number
>c1 : number
>[1, 2] : [number, number]
>1 : number
>2 : number
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
>c2 : number
>c3 : number
>[1, 2, true] : [number, number, boolean]
>1 : number
>2 : number
>true : boolean
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
>temp : string[]
>["s", "t", "r"] : string[]
>"s" : string
>"t" : string
>"r" : string
var temp1 = [1, 2, 3];
>temp1 : number[]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
>temp2 : [number[], string[]]
>[[1, 2, 3], ["hello", "string"]] : [number[], string[]]
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
>["hello", "string"] : string[]
>"hello" : string
>"string" : string
interface myArray extends Array<Number> { }
>myArray : myArray
>Array : T[]
>Number : Number
interface myArray2 extends Array<Number|String> { }
>myArray2 : myArray2
>Array : T[]
>Number : Number
>String : String
var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[]
>d0 : (string | number | boolean)[]
>[1, true, ...temp, ] : (string | number | boolean)[]
>1 : number
>true : boolean
>...temp : string
>temp : string[]
var d1 = [...temp]; // has type string[]
>d1 : string[]
>[...temp] : string[]
>...temp : string
>temp : string[]
var d2: number[] = [...temp1];
>d2 : number[]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
var d3: myArray = [...temp1];
>d3 : myArray
>myArray : myArray
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
var d4: myArray2 = [...temp, ...temp1];
>d4 : myArray2
>myArray2 : myArray2
>[...temp, ...temp1] : (string | number)[]
>...temp : string
>temp : string[]
>...temp1 : number
>temp1 : number[]
var d5 = [...a2];
>d5 : (string | number)[]
>[...a2] : (string | number)[]
>...a2 : string | number
>a2 : (string | number)[]
var d6 = [...a3];
>d6 : number[]
>[...a3] : number[]
>...a3 : number
>a3 : number[]
var d7 = [...a4];
>d7 : (() => number)[]
>[...a4] : (() => number)[]
>...a4 : () => number
>a4 : (() => number)[]
var d8: number[][] = [[...temp1]]
>d8 : number[][]
>[[...temp1]] : number[][]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
var d9 = [[...temp1], ...["hello"]];
>d9 : (string | number[])[]
>[[...temp1], ...["hello"]] : (string | number[])[]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]
>...["hello"] : string
>["hello"] : string[]
>"hello" : string

View File

@@ -0,0 +1,86 @@
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(10,5): error TS2322: Type 'undefined[]' is not assignable to type '[any, any, any]'.
Property '0' is missing in type 'undefined[]'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,5): error TS2322: Type '[string, number, boolean]' is not assignable to type '[boolean, string, number]'.
Types of property '0' are incompatible.
Type 'string' is not assignable to type 'boolean'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
Types of property 'pop' are incompatible.
Type '() => string | number | boolean' is not assignable to type '() => number'.
Type 'string | number | boolean' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'.
Property '0' is missing in type '(string[] | number[])[]'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
Property '0' is missing in type 'number[]'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
Types of property 'push' are incompatible.
Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'.
Types of parameters 'items' and 'items' are incompatible.
Type 'string | number' is not assignable to type 'Number'.
Type 'string' is not assignable to type 'Number'.
Property 'toFixed' is missing in type 'String'.
==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (6 errors) ====
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var a0: [any, any, any] = []; // Error
~~
!!! error TS2322: Type 'undefined[]' is not assignable to type '[any, any, any]'.
!!! error TS2322: Property '0' is missing in type 'undefined[]'.
var a1: [boolean, string, number] = ["string", 1, true]; // Error
~~
!!! error TS2322: Type '[string, number, boolean]' is not assignable to type '[boolean, string, number]'.
!!! error TS2322: Types of property '0' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [b1, b2]: [number, number] = [1, 2, "string", true];
~~~~~~~~
!!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'.
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
interface tup {
0: number[]|string[];
1: number[]|string[];
}
interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var c0: tup = [...temp2]; // Error
~~
!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'.
!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'.
var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number]
~~
!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
!!! error TS2322: Property '0' is missing in type 'number[]'.
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
~~
!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
!!! error TS2322: Types of property 'push' are incompatible.
!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'.
!!! error TS2322: Types of parameters 'items' and 'items' are incompatible.
!!! error TS2322: Type 'string | number' is not assignable to type 'Number'.
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
!!! error TS2322: Property 'toFixed' is missing in type 'String'.

View File

@@ -0,0 +1,60 @@
//// [arrayLiterals3.ts]
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var a0: [any, any, any] = []; // Error
var a1: [boolean, string, number] = ["string", 1, true]; // Error
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [b1, b2]: [number, number] = [1, 2, "string", true];
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
interface tup {
0: number[]|string[];
1: number[]|string[];
}
interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var c0: tup = [...temp2]; // Error
var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number]
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
//// [arrayLiterals3.js]
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var a0 = []; // Error
var a1 = ["string", 1, true]; // Error
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var _a = [1, 2, "string", true], b1 = _a[0], b2 = _a[1];
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2 = [[1, 2, 3], ["hello", "string"]];
var c0 = temp2; // Error
var c1 = temp1; // Error cannot assign number[] to [number, number, number]
var c2 = temp1.concat(temp); // Error cannot assign (number|string)[] to number[]

View File

@@ -0,0 +1,56 @@
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [,, 2, 3, 4]
var a1 = ["hello", "world"]
var a2 = [, , , ...a0, "hello"];
var a3 = [,, ...a0]
var a4 = [() => 1, ];
var a5 = [...a0, , ]
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
var temp3 = [undefined, null, undefined];
var temp4 = [];
interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
var d1 = [...temp]; // has type string[]
var d2: number[] = [...temp1];
var d3: myArray = [...temp1];
var d4: myArray2 = [...temp, ...temp1];
var d5 = [...temp3];
var d6 = [...temp4];
var d7 = [...[...temp1]];
var d8: number[][] = [[...temp1]]
var d9 = [[...temp1], ...["hello"]];

View File

@@ -0,0 +1,55 @@
// @target:es6
// ElementList: ( Modified )
// Elisionopt AssignmentExpression
// Elisionopt SpreadElement
// ElementList, Elisionopt AssignmentExpression
// ElementList, Elisionopt SpreadElement
// SpreadElement:
// ... AssignmentExpression
var a0 = [, , 2, 3, 4]
var a1 = ["hello", "world"]
var a2 = [, , , ...a0, "hello"];
var a3 = [, , ...a0]
var a4 = [() => 1, ];
var a5 = [...a0, , ]
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var b0: [any, any, any] = [undefined, null, undefined];
var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [c0, c1] = [1, 2]; // tuple type [number, number]
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[]
var d1 = [...temp]; // has type string[]
var d2: number[] = [...temp1];
var d3: myArray = [...temp1];
var d4: myArray2 = [...temp, ...temp1];
var d5 = [...a2];
var d6 = [...a3];
var d7 = [...a4];
var d8: number[][] = [[...temp1]]
var d9 = [[...temp1], ...["hello"]];

View File

@@ -0,0 +1,34 @@
// Each element expression in a non-empty array literal is processed as follows:
// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19)
// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal,
// the element expression is contextually typed by the type of that property.
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is contextually typed by a tuple-like type,
// the resulting type is a tuple type constructed from the types of the element expressions.
var a0: [any, any, any] = []; // Error
var a1: [boolean, string, number] = ["string", 1, true]; // Error
// The resulting type an array literal expression is determined as follows:
// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1),
// the resulting type is a tuple type constructed from the types of the element expressions.
var [b1, b2]: [number, number] = [1, 2, "string", true];
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the
// non - spread element expressions and the numeric index signature types of the spread element expressions
var temp = ["s", "t", "r"];
var temp1 = [1, 2, 3];
var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]];
interface tup {
0: number[]|string[];
1: number[]|string[];
}
interface myArray extends Array<Number> { }
interface myArray2 extends Array<Number|String> { }
var c0: tup = [...temp2]; // Error
var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number]
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]