mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-21 08:25:43 -05:00
Add spec description to the test file and move tests that generate errors to separate file
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts(23,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/arrayLiterals2.ts(24,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/arrayLiterals2.ts(27,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/arrayLiterals2.ts (3 errors) ====
|
||||
var a = [2,3,4]
|
||||
var a1 = ["hello", "world"]
|
||||
var a2 = [undefined, null, undefined];
|
||||
var a3 = []
|
||||
var a4: number[] = [...a3];
|
||||
var a5: number[] = [];
|
||||
|
||||
var b = [, , , ...a,"hello"];
|
||||
var c = [() => 1,];
|
||||
var d = [...c,,];
|
||||
var e = [,,...d];
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = [...g];
|
||||
var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]];
|
||||
var j = [...i];
|
||||
var k:Array<number[]|string[]> = [...i];
|
||||
interface tup {
|
||||
0: number[]|string[];
|
||||
1: number[]|string[];
|
||||
}
|
||||
interface myArray extends Array<Number> {}
|
||||
interface myArray2 extends Array<Number|String> {}
|
||||
var l: tup = [...i]; // error
|
||||
~
|
||||
!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'.
|
||||
!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'.
|
||||
var m: [number, number, number] = [...a]; // error
|
||||
~
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
|
||||
!!! error TS2322: Property '0' is missing in type 'number[]'.
|
||||
var n: number[] = [...a];
|
||||
var o: myArray = [...a];
|
||||
var p: myArray = [...a, ...a1]; // error
|
||||
~
|
||||
!!! 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'.
|
||||
var q: myArray2 = [...a, ...a1];
|
||||
var r = [...a2];
|
||||
var r1 = [...a3];
|
||||
var r2 = [...a4];
|
||||
var r3:number[][] = [[...a4]];
|
||||
@@ -1,60 +0,0 @@
|
||||
//// [arrayLiterals2.ts]
|
||||
var a = [2,3,4]
|
||||
var a1 = ["hello", "world"]
|
||||
var a2 = [undefined, null, undefined];
|
||||
var a3 = []
|
||||
var a4: number[] = [...a3];
|
||||
var a5: number[] = [];
|
||||
|
||||
var b = [, , , ...a,"hello"];
|
||||
var c = [() => 1,];
|
||||
var d = [...c,,];
|
||||
var e = [,,...d];
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = [...g];
|
||||
var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]];
|
||||
var j = [...i];
|
||||
var k:Array<number[]|string[]> = [...i];
|
||||
interface tup {
|
||||
0: number[]|string[];
|
||||
1: number[]|string[];
|
||||
}
|
||||
interface myArray extends Array<Number> {}
|
||||
interface myArray2 extends Array<Number|String> {}
|
||||
var l: tup = [...i]; // error
|
||||
var m: [number, number, number] = [...a]; // error
|
||||
var n: number[] = [...a];
|
||||
var o: myArray = [...a];
|
||||
var p: myArray = [...a, ...a1]; // error
|
||||
var q: myArray2 = [...a, ...a1];
|
||||
var r = [...a2];
|
||||
var r1 = [...a3];
|
||||
var r2 = [...a4];
|
||||
var r3:number[][] = [[...a4]];
|
||||
|
||||
//// [arrayLiterals2.js]
|
||||
var a = [2, 3, 4];
|
||||
var a1 = ["hello", "world"];
|
||||
var a2 = [undefined, null, undefined];
|
||||
var a3 = [];
|
||||
var a4 = a3;
|
||||
var a5 = [];
|
||||
var b = [, , ].concat(a, ["hello"]);
|
||||
var c = [function () { return 1; },];
|
||||
var d = c.concat([,]);
|
||||
var e = [, ].concat(d);
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = g;
|
||||
var i = [[1, 2, 3], ["hello", "string"]];
|
||||
var j = i;
|
||||
var k = i;
|
||||
var l = i; // error
|
||||
var m = a; // error
|
||||
var n = a;
|
||||
var o = a;
|
||||
var p = a.concat(a1); // error
|
||||
var q = a.concat(a1);
|
||||
var r = a2;
|
||||
var r1 = a3;
|
||||
var r2 = a4;
|
||||
var r3 = [a4];
|
||||
104
tests/baselines/reference/arrayLiterals2ES5.js
Normal file
104
tests/baselines/reference/arrayLiterals2ES5.js
Normal 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"]);
|
||||
184
tests/baselines/reference/arrayLiterals2ES5.types
Normal file
184
tests/baselines/reference/arrayLiterals2ES5.types
Normal file
@@ -0,0 +1,184 @@
|
||||
=== 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[]
|
||||
|
||||
var a1 = ["hello", "world"]
|
||||
>a1 : string[]
|
||||
>["hello", "world"] : string[]
|
||||
|
||||
var a2 = [, , , ...a0, "hello"];
|
||||
>a2 : (string | number)[]
|
||||
>[, , , ...a0, "hello"] : (string | number)[]
|
||||
>...a0 : number
|
||||
>a0 : number[]
|
||||
|
||||
var a3 = [,, ...a0]
|
||||
>a3 : number[]
|
||||
>[,, ...a0] : number[]
|
||||
>...a0 : number
|
||||
>a0 : number[]
|
||||
|
||||
var a4 = [() => 1, ];
|
||||
>a4 : (() => number)[]
|
||||
>[() => 1, ] : (() => number)[]
|
||||
>() => 1 : () => number
|
||||
|
||||
var a5 = [...a0, , ]
|
||||
>a5 : number[]
|
||||
>[...a0, , ] : number[]
|
||||
>...a0 : number
|
||||
>a0 : number[]
|
||||
|
||||
// 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
|
||||
>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[]
|
||||
>["hello", "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]
|
||||
|
||||
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
|
||||
>c2 : number
|
||||
>c3 : number
|
||||
>[1, 2, true] : [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"];
|
||||
>temp : string[]
|
||||
>["s", "t", "r"] : string[]
|
||||
|
||||
var temp1 = [1, 2, 3];
|
||||
>temp1 : number[]
|
||||
>[1, 2, 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[]
|
||||
>["hello", "string"] : string[]
|
||||
|
||||
var temp3 = [undefined, null, undefined];
|
||||
>temp3 : any[]
|
||||
>[undefined, null, undefined] : null[]
|
||||
>undefined : undefined
|
||||
>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)[]
|
||||
>...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[]
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts(23,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/arrayLiterals2ES6.ts(24,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/arrayLiterals2ES6.ts(27,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/arrayLiterals2ES6.ts (3 errors) ====
|
||||
var a = [2,3,4]
|
||||
var a1 = ["hello", "world"]
|
||||
var a2 = [undefined, null, undefined];
|
||||
var a3 = []
|
||||
var a4: number[] = [...a3];
|
||||
var a5: number[] = [];
|
||||
|
||||
var b = [, , , ...a,"hello"];
|
||||
var c = [() => 1,];
|
||||
var d = [...c,,];
|
||||
var e = [,,...d];
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = [...g];
|
||||
var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]];
|
||||
var j = [...i];
|
||||
var k:Array<number[]|string[]> = [...i];
|
||||
interface tup {
|
||||
0: number[]|string[];
|
||||
1: number[]|string[];
|
||||
}
|
||||
interface myArray extends Array<Number> {}
|
||||
interface myArray2 extends Array<Number|String> {}
|
||||
var l: tup = [...i]; // error
|
||||
~
|
||||
!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'.
|
||||
!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'.
|
||||
var m: [number, number, number] = [...a]; // error
|
||||
~
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
|
||||
!!! error TS2322: Property '0' is missing in type 'number[]'.
|
||||
var n: number[] = [...a];
|
||||
var o: myArray = [...a];
|
||||
var p: myArray = [...a, ...a1]; // error
|
||||
~
|
||||
!!! 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'.
|
||||
var q: myArray2 = [...a, ...a1];
|
||||
var r = [...a2];
|
||||
var r1 = [...a3];
|
||||
var r2 = [...a4];
|
||||
var r3:number[][] = [[...a4]];
|
||||
@@ -1,60 +1,100 @@
|
||||
//// [arrayLiterals2ES6.ts]
|
||||
var a = [2,3,4]
|
||||
var a1 = ["hello", "world"]
|
||||
var a2 = [undefined, null, undefined];
|
||||
var a3 = []
|
||||
var a4: number[] = [...a3];
|
||||
var a5: number[] = [];
|
||||
// ElementList: ( Modified )
|
||||
// Elisionopt AssignmentExpression
|
||||
// Elisionopt SpreadElement
|
||||
// ElementList, Elisionopt AssignmentExpression
|
||||
// ElementList, Elisionopt SpreadElement
|
||||
|
||||
var b = [, , , ...a,"hello"];
|
||||
var c = [() => 1,];
|
||||
var d = [...c,,];
|
||||
var e = [,,...d];
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = [...g];
|
||||
var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]];
|
||||
var j = [...i];
|
||||
var k:Array<number[]|string[]> = [...i];
|
||||
interface tup {
|
||||
0: number[]|string[];
|
||||
1: number[]|string[];
|
||||
}
|
||||
interface myArray extends Array<Number> {}
|
||||
interface myArray2 extends Array<Number|String> {}
|
||||
var l: tup = [...i]; // error
|
||||
var m: [number, number, number] = [...a]; // error
|
||||
var n: number[] = [...a];
|
||||
var o: myArray = [...a];
|
||||
var p: myArray = [...a, ...a1]; // error
|
||||
var q: myArray2 = [...a, ...a1];
|
||||
var r = [...a2];
|
||||
var r1 = [...a3];
|
||||
var r2 = [...a4];
|
||||
var r3:number[][] = [[...a4]];
|
||||
// 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]
|
||||
var a = [2, 3, 4];
|
||||
// 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 = [undefined, null, undefined];
|
||||
var a3 = [];
|
||||
var a4 = [...a3];
|
||||
var a5 = [];
|
||||
var b = [, , , ...a, "hello"];
|
||||
var c = [() => 1,];
|
||||
var d = [...c, ,];
|
||||
var e = [, , ...d];
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = [...g];
|
||||
var i = [[1, 2, 3], ["hello", "string"]];
|
||||
var j = [...i];
|
||||
var k = [...i];
|
||||
var l = [...i]; // error
|
||||
var m = [...a]; // error
|
||||
var n = [...a];
|
||||
var o = [...a];
|
||||
var p = [...a, ...a1]; // error
|
||||
var q = [...a, ...a1];
|
||||
var r = [...a2];
|
||||
var r1 = [...a3];
|
||||
var r2 = [...a4];
|
||||
var r3 = [[...a4]];
|
||||
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"]];
|
||||
|
||||
172
tests/baselines/reference/arrayLiterals2ES6.types
Normal file
172
tests/baselines/reference/arrayLiterals2ES6.types
Normal file
@@ -0,0 +1,172 @@
|
||||
=== 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[]
|
||||
|
||||
var a1 = ["hello", "world"]
|
||||
>a1 : string[]
|
||||
>["hello", "world"] : string[]
|
||||
|
||||
var a2 = [, , , ...a0, "hello"];
|
||||
>a2 : (string | number)[]
|
||||
>[, , , ...a0, "hello"] : (string | number)[]
|
||||
>...a0 : number
|
||||
>a0 : number[]
|
||||
|
||||
var a3 = [, , ...a0]
|
||||
>a3 : number[]
|
||||
>[, , ...a0] : number[]
|
||||
>...a0 : number
|
||||
>a0 : number[]
|
||||
|
||||
var a4 = [() => 1, ];
|
||||
>a4 : (() => number)[]
|
||||
>[() => 1, ] : (() => number)[]
|
||||
>() => 1 : () => number
|
||||
|
||||
var a5 = [...a0, , ]
|
||||
>a5 : number[]
|
||||
>[...a0, , ] : number[]
|
||||
>...a0 : number
|
||||
>a0 : number[]
|
||||
|
||||
// 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
|
||||
>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[]
|
||||
>["hello", "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]
|
||||
|
||||
var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean]
|
||||
>c2 : number
|
||||
>c3 : number
|
||||
>[1, 2, true] : [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"];
|
||||
>temp : string[]
|
||||
>["s", "t", "r"] : string[]
|
||||
|
||||
var temp1 = [1, 2, 3];
|
||||
>temp1 : number[]
|
||||
>[1, 2, 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[]
|
||||
>["hello", "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)[]
|
||||
>...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[]
|
||||
|
||||
@@ -1,62 +1,86 @@
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(8,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
|
||||
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(35,6): error TS2461: Type 'string | number[]' is not an array type.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(40,16): error TS2461: Type 'IArguments' is not an array type.
|
||||
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 (3 errors) ====
|
||||
interface I0 extends Array<String|Number|Boolean> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string;
|
||||
3: boolean;
|
||||
}
|
||||
var [a, b]: [number, number] = [1, 2];
|
||||
var [a1, b1]: [number, number] = [1, 2, "string", true]; // error
|
||||
==== 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'.
|
||||
var [a2, b2]: (number| string)[] = [1, 2, 3, "string"];
|
||||
var [c1, c2, c3]: I0 = [10, 11, "string", true];
|
||||
interface I extends Array<String|Number>{
|
||||
0: string|number;
|
||||
1: string|number;
|
||||
2: string|number;
|
||||
}
|
||||
interface I2 extends Array<String|Number> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string|number;
|
||||
}
|
||||
var tup: [number, number, string] = [1, 2, "world"];
|
||||
var [c, d, e]: I = tup;
|
||||
var [f, g]: I2 = tup;
|
||||
var h1: string| number;
|
||||
var [f1, g1,h1]: I2 = tup;
|
||||
h1 = g1;
|
||||
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true]
|
||||
var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]];
|
||||
var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2];
|
||||
var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3];
|
||||
var [[r, s], t] = [[...arr1], "hello"];
|
||||
var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error
|
||||
~~~~~~~~
|
||||
!!! error TS2461: Type 'string | number[]' is not an array type.
|
||||
var [x] = [...["word"]];
|
||||
var [...y] = [...["word"]];
|
||||
var z = [...[...["word"]]];
|
||||
function foobar() {
|
||||
return [...arguments];
|
||||
~~~~~~~~~
|
||||
!!! error TS2461: Type 'IArguments' is not an array type.
|
||||
// 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[];
|
||||
}
|
||||
var [...as] = [[, , , , ]];
|
||||
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'.
|
||||
|
||||
@@ -1,70 +1,60 @@
|
||||
//// [arrayLiterals3.ts]
|
||||
interface I0 extends Array<String|Number|Boolean> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string;
|
||||
3: boolean;
|
||||
}
|
||||
var [a, b]: [number, number] = [1, 2];
|
||||
var [a1, b1]: [number, number] = [1, 2, "string", true]; // error
|
||||
var [a2, b2]: (number| string)[] = [1, 2, 3, "string"];
|
||||
var [c1, c2, c3]: I0 = [10, 11, "string", true];
|
||||
interface I extends Array<String|Number>{
|
||||
0: string|number;
|
||||
1: string|number;
|
||||
2: string|number;
|
||||
}
|
||||
interface I2 extends Array<String|Number> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string|number;
|
||||
}
|
||||
var tup: [number, number, string] = [1, 2, "world"];
|
||||
var [c, d, e]: I = tup;
|
||||
var [f, g]: I2 = tup;
|
||||
var h1: string| number;
|
||||
var [f1, g1,h1]: I2 = tup;
|
||||
h1 = g1;
|
||||
// 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.
|
||||
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true]
|
||||
var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]];
|
||||
var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2];
|
||||
var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3];
|
||||
var [[r, s], t] = [[...arr1], "hello"];
|
||||
var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error
|
||||
var [x] = [...["word"]];
|
||||
var [...y] = [...["word"]];
|
||||
var z = [...[...["word"]]];
|
||||
function foobar() {
|
||||
return [...arguments];
|
||||
// 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[];
|
||||
}
|
||||
var [...as] = [[, , , , ]];
|
||||
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]
|
||||
var _a = [1, 2], a = _a[0], b = _a[1];
|
||||
var _b = [1, 2, "string", true], a1 = _b[0], b1 = _b[1]; // error
|
||||
var _c = [1, 2, 3, "string"], a2 = _c[0], b2 = _c[1];
|
||||
var _d = [10, 11, "string", true], c1 = _d[0], c2 = _d[1], c3 = _d[2];
|
||||
var tup = [1, 2, "world"];
|
||||
var c = tup[0], d = tup[1], e = tup[2];
|
||||
var f = tup[0], g = tup[1];
|
||||
var h1;
|
||||
var f1 = tup[0], g1 = tup[1], h1 = tup[2];
|
||||
h1 = g1;
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true];
|
||||
var _e = [arr1, arr2], _f = _e[0], foo1 = _f[0], foo2 = _f[1], foo3 = _f[2], _g = _e[1], boo1 = _g[0], boo2 = _g[1], boo3 = _g[2];
|
||||
var _h = arr1.concat(arr2), bar1 = _h[0], bar2 = _h[1], bar3 = _h[2], bar1 = _h[3], bar2 = _h[4], bar3 = _h[5];
|
||||
var _j = arr1.concat(arr3), bar1 = _j[0], bar2 = _j[1], bar3 = _j[2], bar1 = _j[3], bar2 = _j[4];
|
||||
var _k = [arr1, "hello"], _l = _k[0], r = _l[0], s = _l[1], t = _k[1];
|
||||
var _m = [arr1].concat(["hello"]), _o = _m[0], r1 = _o[0], s1 = _o[1], t1 = _m[1]; // error
|
||||
var x = (["word"])[0];
|
||||
var _p = ["word"], y = _p.slice(0);
|
||||
var z = ["word"];
|
||||
function foobar() {
|
||||
return arguments;
|
||||
}
|
||||
var _q = [[, , , ,]], as = _q.slice(0);
|
||||
// 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[]
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts(8,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/arrayLiterals3ES6.ts (1 errors) ====
|
||||
interface I0 extends Array<String|Number|Boolean> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string;
|
||||
3: boolean;
|
||||
}
|
||||
var [a, b]: [number, number] = [1, 2];
|
||||
var [a1, b1]: [number, number] = [1, 2, "string", true]; // error
|
||||
~~~~~~~~
|
||||
!!! 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'.
|
||||
var [a2, b2]: (number| string)[] = [1, 2, 3, "string"];
|
||||
var [c1, c2, c3]: I0 = [10, 11, "string", true];
|
||||
interface I extends Array<String|Number>{
|
||||
0: string|number;
|
||||
1: string|number;
|
||||
2: string|number;
|
||||
}
|
||||
interface I2 extends Array<String|Number> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string|number;
|
||||
}
|
||||
var tup: [number, number, string] = [1, 2, "world"];
|
||||
var [c, d, e]: I = tup;
|
||||
var [f, g]: I2 = tup;
|
||||
var h1: string| number;
|
||||
var [f1, g1,h1]: I2 = tup;
|
||||
h1 = g1;
|
||||
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true]
|
||||
var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]];
|
||||
var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2];
|
||||
var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3];
|
||||
var [[r, s], t] = [[...arr1], "hello"];
|
||||
var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error
|
||||
var [x] = [...["word"]];
|
||||
var [...y] = [...["word"]];
|
||||
var z = [...[...["word"]]];
|
||||
@@ -1,62 +0,0 @@
|
||||
//// [arrayLiterals3ES6.ts]
|
||||
interface I0 extends Array<String|Number|Boolean> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string;
|
||||
3: boolean;
|
||||
}
|
||||
var [a, b]: [number, number] = [1, 2];
|
||||
var [a1, b1]: [number, number] = [1, 2, "string", true]; // error
|
||||
var [a2, b2]: (number| string)[] = [1, 2, 3, "string"];
|
||||
var [c1, c2, c3]: I0 = [10, 11, "string", true];
|
||||
interface I extends Array<String|Number>{
|
||||
0: string|number;
|
||||
1: string|number;
|
||||
2: string|number;
|
||||
}
|
||||
interface I2 extends Array<String|Number> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string|number;
|
||||
}
|
||||
var tup: [number, number, string] = [1, 2, "world"];
|
||||
var [c, d, e]: I = tup;
|
||||
var [f, g]: I2 = tup;
|
||||
var h1: string| number;
|
||||
var [f1, g1,h1]: I2 = tup;
|
||||
h1 = g1;
|
||||
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true]
|
||||
var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]];
|
||||
var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2];
|
||||
var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3];
|
||||
var [[r, s], t] = [[...arr1], "hello"];
|
||||
var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error
|
||||
var [x] = [...["word"]];
|
||||
var [...y] = [...["word"]];
|
||||
var z = [...[...["word"]]];
|
||||
|
||||
//// [arrayLiterals3ES6.js]
|
||||
var [a, b] = [1, 2];
|
||||
var [a1, b1] = [1, 2, "string", true]; // error
|
||||
var [a2, b2] = [1, 2, 3, "string"];
|
||||
var [c1, c2, c3] = [10, 11, "string", true];
|
||||
var tup = [1, 2, "world"];
|
||||
var [c, d, e] = tup;
|
||||
var [f, g] = tup;
|
||||
var h1;
|
||||
var [f1, g1, h1] = tup;
|
||||
h1 = g1;
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true];
|
||||
var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]];
|
||||
var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2];
|
||||
var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3];
|
||||
var [[r, s], t] = [[...arr1], "hello"];
|
||||
var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error
|
||||
var [x] = [...["word"]];
|
||||
var [...y] = [...["word"]];
|
||||
var z = [...[...["word"]]];
|
||||
@@ -1,31 +0,0 @@
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(2,14): error TS1212: Identifier expected. 'static' is a reserved word in strict mode
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(3,5): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(4,21): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(5,7): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(5,15): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(6,9): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts (7 errors) ====
|
||||
"use strict"
|
||||
var [public, static] = [1, 23, ];
|
||||
~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode
|
||||
~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode
|
||||
var protected = [1, 2, 3];
|
||||
~~~~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
|
||||
var [a, b, c] = [...protected];
|
||||
~~~~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
|
||||
var [[public, package]] = [[1, [2, 3]]];
|
||||
~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode
|
||||
~~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode
|
||||
var [...implements] = [[]];
|
||||
~~~~~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
//// [arrayLiterals4.ts]
|
||||
"use strict"
|
||||
var [public, static] = [1, 23, ];
|
||||
var protected = [1, 2, 3];
|
||||
var [a, b, c] = [...protected];
|
||||
var [[public, package]] = [[1, [2, 3]]];
|
||||
var [...implements] = [[]];
|
||||
|
||||
|
||||
//// [arrayLiterals4.js]
|
||||
"use strict";
|
||||
var _a = [1, 23,], public = _a[0], static = _a[1];
|
||||
var protected = [1, 2, 3];
|
||||
var _b = protected, a = _b[0], b = _b[1], c = _b[2];
|
||||
var _c = ([[1, [2, 3]]])[0], public = _c[0], package = _c[1];
|
||||
var _d = [[]], implements = _d.slice(0);
|
||||
@@ -1,46 +0,0 @@
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,6): error TS1181: Array element destructuring pattern expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,11): error TS1005: '(' expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,13): error TS1109: Expression expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,16): error TS1005: '(' expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,18): error TS1128: Declaration or statement expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,6): error TS1181: Array element destructuring pattern expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,9): error TS1005: '(' expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,11): error TS2304: Cannot find name 'as'.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,13): error TS1005: ';' expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,15): error TS1128: Declaration or statement expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,9): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,14): error TS1003: Identifier expected.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,16): error TS1128: Declaration or statement expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts (13 errors) ====
|
||||
var [while, for] = [1, 3, ];
|
||||
~~~~~
|
||||
!!! error TS1181: Array element destructuring pattern expected.
|
||||
~
|
||||
!!! error TS1005: '(' expected.
|
||||
~~~
|
||||
!!! error TS1109: Expression expected.
|
||||
~
|
||||
!!! error TS1005: '(' expected.
|
||||
~
|
||||
!!! error TS1128: Declaration or statement expected.
|
||||
var [for, as] = [, , , , ];
|
||||
~~~
|
||||
!!! error TS1181: Array element destructuring pattern expected.
|
||||
~
|
||||
!!! error TS1005: '(' expected.
|
||||
~~
|
||||
!!! error TS2304: Cannot find name 'as'.
|
||||
~
|
||||
!!! error TS1005: ';' expected.
|
||||
~
|
||||
!!! error TS1128: Declaration or statement expected.
|
||||
var [...break] = [...["hello"]];
|
||||
~~~~~
|
||||
!!! error TS1003: Identifier expected.
|
||||
~
|
||||
!!! error TS1003: Identifier expected.
|
||||
~
|
||||
!!! error TS1128: Declaration or statement expected.
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
//// [arrayLiterals5.ts]
|
||||
var [while, for] = [1, 3, ];
|
||||
var [for, as] = [, , , , ];
|
||||
var [...break] = [...["hello"]];
|
||||
|
||||
|
||||
//// [arrayLiterals5.js]
|
||||
var _a = void 0;
|
||||
while (, )
|
||||
for (; ; )
|
||||
;
|
||||
[1, 3,];
|
||||
var _b = void 0;
|
||||
for (, as; ; )
|
||||
;
|
||||
[, , , ,];
|
||||
var _c = void 0, = _c.slice(0);
|
||||
break ;
|
||||
["hello"];
|
||||
@@ -1,32 +0,0 @@
|
||||
var a = [2,3,4]
|
||||
var a1 = ["hello", "world"]
|
||||
var a2 = [undefined, null, undefined];
|
||||
var a3 = []
|
||||
var a4: number[] = [...a3];
|
||||
var a5: number[] = [];
|
||||
|
||||
var b = [, , , ...a,"hello"];
|
||||
var c = [() => 1,];
|
||||
var d = [...c,,];
|
||||
var e = [,,...d];
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = [...g];
|
||||
var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]];
|
||||
var j = [...i];
|
||||
var k:Array<number[]|string[]> = [...i];
|
||||
interface tup {
|
||||
0: number[]|string[];
|
||||
1: number[]|string[];
|
||||
}
|
||||
interface myArray extends Array<Number> {}
|
||||
interface myArray2 extends Array<Number|String> {}
|
||||
var l: tup = [...i]; // error
|
||||
var m: [number, number, number] = [...a]; // error
|
||||
var n: number[] = [...a];
|
||||
var o: myArray = [...a];
|
||||
var p: myArray = [...a, ...a1]; // error
|
||||
var q: myArray2 = [...a, ...a1];
|
||||
var r = [...a2];
|
||||
var r1 = [...a3];
|
||||
var r2 = [...a4];
|
||||
var r3:number[][] = [[...a4]];
|
||||
@@ -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"]];
|
||||
@@ -1,33 +1,55 @@
|
||||
// @target:es6
|
||||
var a = [2,3,4]
|
||||
var a1 = ["hello", "world"]
|
||||
var a2 = [undefined, null, undefined];
|
||||
var a3 = []
|
||||
var a4: number[] = [...a3];
|
||||
var a5: number[] = [];
|
||||
// ElementList: ( Modified )
|
||||
// Elisionopt AssignmentExpression
|
||||
// Elisionopt SpreadElement
|
||||
// ElementList, Elisionopt AssignmentExpression
|
||||
// ElementList, Elisionopt SpreadElement
|
||||
|
||||
var b = [, , , ...a,"hello"];
|
||||
var c = [() => 1,];
|
||||
var d = [...c,,];
|
||||
var e = [,,...d];
|
||||
var g = [[1, 2, "hello"], ["string", true]];
|
||||
var h = [...g];
|
||||
var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]];
|
||||
var j = [...i];
|
||||
var k:Array<number[]|string[]> = [...i];
|
||||
interface tup {
|
||||
0: number[]|string[];
|
||||
1: number[]|string[];
|
||||
}
|
||||
interface myArray extends Array<Number> {}
|
||||
interface myArray2 extends Array<Number|String> {}
|
||||
var l: tup = [...i]; // error
|
||||
var m: [number, number, number] = [...a]; // error
|
||||
var n: number[] = [...a];
|
||||
var o: myArray = [...a];
|
||||
var p: myArray = [...a, ...a1]; // error
|
||||
var q: myArray2 = [...a, ...a1];
|
||||
var r = [...a2];
|
||||
var r1 = [...a3];
|
||||
var r2 = [...a4];
|
||||
var r3:number[][] = [[...a4]];
|
||||
// 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"]];
|
||||
@@ -1,42 +1,34 @@
|
||||
interface I0 extends Array<String|Number|Boolean> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string;
|
||||
3: boolean;
|
||||
}
|
||||
var [a, b]: [number, number] = [1, 2];
|
||||
var [a1, b1]: [number, number] = [1, 2, "string", true]; // error
|
||||
var [a2, b2]: (number| string)[] = [1, 2, 3, "string"];
|
||||
var [c1, c2, c3]: I0 = [10, 11, "string", true];
|
||||
interface I extends Array<String|Number>{
|
||||
0: string|number;
|
||||
1: string|number;
|
||||
2: string|number;
|
||||
}
|
||||
interface I2 extends Array<String|Number> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string|number;
|
||||
}
|
||||
var tup: [number, number, string] = [1, 2, "world"];
|
||||
var [c, d, e]: I = tup;
|
||||
var [f, g]: I2 = tup;
|
||||
var h1: string| number;
|
||||
var [f1, g1,h1]: I2 = tup;
|
||||
h1 = g1;
|
||||
// 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.
|
||||
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true]
|
||||
var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]];
|
||||
var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2];
|
||||
var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3];
|
||||
var [[r, s], t] = [[...arr1], "hello"];
|
||||
var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error
|
||||
var [x] = [...["word"]];
|
||||
var [...y] = [...["word"]];
|
||||
var z = [...[...["word"]]];
|
||||
function foobar() {
|
||||
return [...arguments];
|
||||
// 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[];
|
||||
}
|
||||
var [...as] = [[, , , , ]];
|
||||
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[]
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
// @target:es6
|
||||
interface I0 extends Array<String|Number|Boolean> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string;
|
||||
3: boolean;
|
||||
}
|
||||
var [a, b]: [number, number] = [1, 2];
|
||||
var [a1, b1]: [number, number] = [1, 2, "string", true]; // error
|
||||
var [a2, b2]: (number| string)[] = [1, 2, 3, "string"];
|
||||
var [c1, c2, c3]: I0 = [10, 11, "string", true];
|
||||
interface I extends Array<String|Number>{
|
||||
0: string|number;
|
||||
1: string|number;
|
||||
2: string|number;
|
||||
}
|
||||
interface I2 extends Array<String|Number> {
|
||||
0: number;
|
||||
1: number;
|
||||
2: string|number;
|
||||
}
|
||||
var tup: [number, number, string] = [1, 2, "world"];
|
||||
var [c, d, e]: I = tup;
|
||||
var [f, g]: I2 = tup;
|
||||
var h1: string| number;
|
||||
var [f1, g1,h1]: I2 = tup;
|
||||
h1 = g1;
|
||||
|
||||
var arr1 = [1, 2, 3];
|
||||
var arr2 = [true, false, true];
|
||||
var arr3 = [true]
|
||||
var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]];
|
||||
var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2];
|
||||
var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3];
|
||||
var [[r, s], t] = [[...arr1], "hello"];
|
||||
var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error
|
||||
var [x] = [...["word"]];
|
||||
var [...y] = [...["word"]];
|
||||
var z = [...[...["word"]]];
|
||||
@@ -1,6 +0,0 @@
|
||||
"use strict"
|
||||
var [public, static] = [1, 23, ];
|
||||
var protected = [1, 2, 3];
|
||||
var [a, b, c] = [...protected];
|
||||
var [[public, package]] = [[1, [2, 3]]];
|
||||
var [...implements] = [[]];
|
||||
@@ -1,3 +0,0 @@
|
||||
var [while, for] = [1, 3, ];
|
||||
var [for, as] = [, , , , ];
|
||||
var [...break] = [...["hello"]];
|
||||
Reference in New Issue
Block a user