177 lines
4.2 KiB
Text
177 lines
4.2 KiB
Text
=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts ===
|
|
|
|
/* AssignmentPattern:
|
|
* ObjectAssignmentPattern
|
|
* ArrayAssignmentPattern
|
|
* ArrayAssignmentPattern:
|
|
* [Elision<opt> AssignmentRestElementopt ]
|
|
* [AssignmentElementList]
|
|
* [AssignmentElementList, Elision<opt> AssignmentRestElementopt ]
|
|
* AssignmentElementList:
|
|
* Elision<opt> AssignmentElement
|
|
* AssignmentElementList, Elisionopt AssignmentElement
|
|
* AssignmentElement:
|
|
* LeftHandSideExpression Initialiseropt
|
|
* AssignmentPattern Initialiseropt
|
|
* AssignmentRestElement:
|
|
* ... LeftHandSideExpression
|
|
*/
|
|
|
|
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
|
|
// An expression of type S is considered assignable to an assignment target V if one of the following is true
|
|
|
|
// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V,
|
|
// S is the type Any, or
|
|
|
|
var [a0, a1]: any = undefined;
|
|
>a0 : any
|
|
>a1 : any
|
|
>undefined : undefined
|
|
|
|
var [a2 = false, a3 = 1]: any = undefined;
|
|
>a2 : boolean
|
|
>false : boolean
|
|
>a3 : number
|
|
>1 : number
|
|
>undefined : undefined
|
|
|
|
// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V,
|
|
// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E,
|
|
// where N is the numeric index of E in the array assignment pattern, or
|
|
var [b0, b1, b2] = [2, 3, 4];
|
|
>b0 : number
|
|
>b1 : number
|
|
>b2 : number
|
|
>[2, 3, 4] : [number, number, number]
|
|
>2 : number
|
|
>3 : number
|
|
>4 : number
|
|
|
|
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
|
|
>b3 : number
|
|
>b4 : number
|
|
>b5 : string
|
|
>[1, 2, "string"] : [number, number, string]
|
|
>1 : number
|
|
>2 : number
|
|
>"string" : string
|
|
|
|
function foo() {
|
|
>foo : () => number[]
|
|
|
|
return [1, 2, 3];
|
|
>[1, 2, 3] : number[]
|
|
>1 : number
|
|
>2 : number
|
|
>3 : number
|
|
}
|
|
|
|
var [b6, b7] = foo();
|
|
>b6 : number
|
|
>b7 : number
|
|
>foo() : number[]
|
|
>foo : () => number[]
|
|
|
|
var [...b8] = foo();
|
|
>b8 : number[]
|
|
>foo() : number[]
|
|
>foo : () => number[]
|
|
|
|
// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E.
|
|
var temp = [1,2,3]
|
|
>temp : number[]
|
|
>[1,2,3] : number[]
|
|
>1 : number
|
|
>2 : number
|
|
>3 : number
|
|
|
|
var [c0, c1] = [...temp];
|
|
>c0 : number
|
|
>c1 : number
|
|
>[...temp] : number[]
|
|
>...temp : number
|
|
>temp : number[]
|
|
|
|
var [c2] = [];
|
|
>c2 : any
|
|
>[] : undefined[]
|
|
|
|
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
|
|
>c3 : any
|
|
>c4 : any
|
|
>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]]
|
|
>[[]] : [undefined[]]
|
|
>[] : undefined[]
|
|
>[[[[]]]] : [[[undefined[]]]]
|
|
>[[[]]] : [[undefined[]]]
|
|
>[[]] : [undefined[]]
|
|
>[] : undefined[]
|
|
|
|
var [[c5], c6]: [[string|number], boolean] = [[1], true];
|
|
>c5 : string | number
|
|
>c6 : boolean
|
|
>[[1], true] : [[number], boolean]
|
|
>[1] : [number]
|
|
>1 : number
|
|
>true : boolean
|
|
|
|
var [, c7] = [1, 2, 3];
|
|
> : undefined
|
|
>c7 : number
|
|
>[1, 2, 3] : [number, number, number]
|
|
>1 : number
|
|
>2 : number
|
|
>3 : number
|
|
|
|
var [,,, c8] = [1, 2, 3, 4];
|
|
> : undefined
|
|
> : undefined
|
|
> : undefined
|
|
>c8 : number
|
|
>[1, 2, 3, 4] : [number, number, number, number]
|
|
>1 : number
|
|
>2 : number
|
|
>3 : number
|
|
>4 : number
|
|
|
|
var [,,, c9] = [1, 2, 3, 4];
|
|
> : undefined
|
|
> : undefined
|
|
> : undefined
|
|
>c9 : number
|
|
>[1, 2, 3, 4] : [number, number, number, number]
|
|
>1 : number
|
|
>2 : number
|
|
>3 : number
|
|
>4 : number
|
|
|
|
var [,,,...c10] = [1, 2, 3, 4, "hello"];
|
|
> : undefined
|
|
> : undefined
|
|
> : undefined
|
|
>c10 : (string | number)[]
|
|
>[1, 2, 3, 4, "hello"] : (string | number)[]
|
|
>1 : number
|
|
>2 : number
|
|
>3 : number
|
|
>4 : number
|
|
>"hello" : string
|
|
|
|
var [c11, c12, ...c13] = [1, 2, "string"];
|
|
>c11 : string | number
|
|
>c12 : string | number
|
|
>c13 : (string | number)[]
|
|
>[1, 2, "string"] : (string | number)[]
|
|
>1 : number
|
|
>2 : number
|
|
>"string" : string
|
|
|
|
var [c14, c15, c16] = [1, 2, "string"];
|
|
>c14 : number
|
|
>c15 : number
|
|
>c16 : string
|
|
>[1, 2, "string"] : [number, number, string]
|
|
>1 : number
|
|
>2 : number
|
|
>"string" : string
|
|
|