Add spec description

This commit is contained in:
Yui T 2015-04-16 18:53:16 -07:00
parent 1d793f4c5e
commit 31da11656e
46 changed files with 2134 additions and 880 deletions

View file

@ -1,41 +0,0 @@
//// [destructuringArrayBindingPatternAndAssignment1.ts]
var [p0,p1, p2] : any = [2, 3, 4];
var [a, b, c]: [number, number, string] = [1, 2, "string"];
var [d, e]: any = undefined;
var [f = false, g = 1]: any = undefined;
g = 10;
f = true;
var [x] = []
var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]]
var [[w], m]: [[string|number], boolean] = [[1], true];
interface J extends Array<Number> {
2: number;
}
var [, w1] = [1, 2, 3];
var [,,, w2] = [1, 2, 3, 4];
var [,,, w2] = [1, 2, 3, 4];
var [,,,...w3] = [1, 2, 3, 4, "hello"];
var [r, s, ...t] = [1, 2, "string"];
var [r1, s1, t1] = [1, 2, "string"];
//// [destructuringArrayBindingPatternAndAssignment1.js]
var _a = [2, 3, 4], p0 = _a[0], p1 = _a[1], p2 = _a[2];
var _b = [1, 2, "string"], a = _b[0], b = _b[1], c = _b[2];
var d = undefined[0], e = undefined[1];
var _c = undefined[0], f = _c === void 0 ? false : _c, _d = undefined[1], g = _d === void 0 ? 1 : _d;
g = 10;
f = true;
var x = ([])[0];
var _e = [[[]], [[[[]]]]], y = _e[0][0][0], z = _e[1][0][0][0][0];
var _f = [[1], true], w = _f[0][0], m = _f[1];
var _g = [1, 2, 3], w1 = _g[1];
var _h = [1, 2, 3, 4], w2 = _h[3];
var _j = [1, 2, 3, 4], w2 = _j[3];
var _k = [1, 2, 3, 4, "hello"], w3 = _k.slice(3);
var _l = [1, 2, "string"], r = _l[0], s = _l[1], t = _l.slice(2);
var _m = [1, 2, "string"], r1 = _m[0], s1 = _m[1], t1 = _m[2];

View file

@ -1,133 +0,0 @@
=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts ===
var [p0,p1, p2] : any = [2, 3, 4];
>p0 : any, Symbol(p0, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 5))
>p1 : any, Symbol(p1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 8))
>p2 : any, Symbol(p2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 11))
>[2, 3, 4] : number[]
>2 : number
>3 : number
>4 : number
var [a, b, c]: [number, number, string] = [1, 2, "string"];
>a : number, Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 5))
>b : number, Symbol(b, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 7))
>c : string, Symbol(c, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 10))
>[1, 2, "string"] : [number, number, string]
>1 : number
>2 : number
>"string" : string
var [d, e]: any = undefined;
>d : any, Symbol(d, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 5))
>e : any, Symbol(e, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 7))
>undefined : undefined, Symbol(undefined)
var [f = false, g = 1]: any = undefined;
>f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5))
>false : boolean
>g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15))
>1 : number
>undefined : undefined, Symbol(undefined)
g = 10;
>g = 10 : number
>g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15))
>10 : number
f = true;
>f = true : boolean
>f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5))
>true : boolean
var [x] = []
>x : any, Symbol(x, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 7, 5))
>[] : undefined[]
var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]]
>y : any, Symbol(y, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 7))
>z : any, Symbol(z, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 16))
>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]]
>[[]] : [undefined[]]
>[] : undefined[]
>[[[[]]]] : [[[undefined[]]]]
>[[[]]] : [[undefined[]]]
>[[]] : [undefined[]]
>[] : undefined[]
var [[w], m]: [[string|number], boolean] = [[1], true];
>w : string | number, Symbol(w, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 6))
>m : boolean, Symbol(m, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 9))
>[[1], true] : [[number], boolean]
>[1] : [number]
>1 : number
>true : boolean
interface J extends Array<Number> {
>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 55))
>Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
2: number;
}
var [, w1] = [1, 2, 3];
> : undefined
>w1 : number, Symbol(w1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 14, 6))
>[1, 2, 3] : [number, number, number]
>1 : number
>2 : number
>3 : number
var [,,, w2] = [1, 2, 3, 4];
> : undefined
> : undefined
> : undefined
>w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8))
>[1, 2, 3, 4] : [number, number, number, number]
>1 : number
>2 : number
>3 : number
>4 : number
var [,,, w2] = [1, 2, 3, 4];
> : undefined
> : undefined
> : undefined
>w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8))
>[1, 2, 3, 4] : [number, number, number, number]
>1 : number
>2 : number
>3 : number
>4 : number
var [,,,...w3] = [1, 2, 3, 4, "hello"];
> : undefined
> : undefined
> : undefined
>w3 : (string | number)[], Symbol(w3, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 17, 8))
>[1, 2, 3, 4, "hello"] : (string | number)[]
>1 : number
>2 : number
>3 : number
>4 : number
>"hello" : string
var [r, s, ...t] = [1, 2, "string"];
>r : string | number, Symbol(r, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 5))
>s : string | number, Symbol(s, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 7))
>t : (string | number)[], Symbol(t, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 10))
>[1, 2, "string"] : (string | number)[]
>1 : number
>2 : number
>"string" : string
var [r1, s1, t1] = [1, 2, "string"];
>r1 : number, Symbol(r1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 5))
>s1 : number, Symbol(s1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 8))
>t1 : string, Symbol(t1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 12))
>[1, 2, "string"] : [number, number, string]
>1 : number
>2 : number
>"string" : string

View file

@ -0,0 +1,100 @@
//// [destructuringArrayBindingPatternAndAssignment1ES5.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;
var [a2 = false, a3 = 1]: any = 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];
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
function foo() {
return [1, 2, 3];
}
var [b6, b7] = foo();
var [...b8] = foo();
// 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]
var [c0, c1] = [...temp];
var [c2] = [];
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
var [[c5], c6]: [[string|number], boolean] = [[1], true];
var [, c7] = [1, 2, 3];
var [,,, c8] = [1, 2, 3, 4];
var [,,, c9] = [1, 2, 3, 4];
var [,,,...c10] = [1, 2, 3, 4, "hello"];
var [c11, c12, ...c13] = [1, 2, "string"];
var [c14, c15, c16] = [1, 2, "string"];
//// [destructuringArrayBindingPatternAndAssignment1ES5.js]
/* 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 = undefined[0], a1 = undefined[1];
var _a = undefined[0], a2 = _a === void 0 ? false : _a, _b = undefined[1], a3 = _b === void 0 ? 1 : _b;
// 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 _c = [2, 3, 4], b0 = _c[0], b1 = _c[1], b2 = _c[2];
var _d = [1, 2, "string"], b3 = _d[0], b4 = _d[1], b5 = _d[2];
function foo() {
return [1, 2, 3];
}
var _e = foo(), b6 = _e[0], b7 = _e[1];
var _f = foo(), b8 = _f.slice(0);
// 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];
var _g = temp, c0 = _g[0], c1 = _g[1];
var c2 = ([])[0];
var _h = [[[]], [[[[]]]]], c3 = _h[0][0][0], c4 = _h[1][0][0][0][0];
var _j = [[1], true], c5 = _j[0][0], c6 = _j[1];
var _k = [1, 2, 3], c7 = _k[1];
var _l = [1, 2, 3, 4], c8 = _l[3];
var _m = [1, 2, 3, 4], c9 = _m[3];
var _o = [1, 2, 3, 4, "hello"], c10 = _o.slice(3);
var _p = [1, 2, "string"], c11 = _p[0], c12 = _p[1], c13 = _p.slice(2);
var _q = [1, 2, "string"], c14 = _q[0], c15 = _q[1], c16 = _q[2];

View file

@ -0,0 +1,177 @@
=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.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, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5))
>a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8))
>undefined : undefined, Symbol(undefined)
var [a2 = false, a3 = 1]: any = undefined;
>a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5))
>false : boolean
>a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16))
>1 : number
>undefined : undefined, Symbol(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, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5))
>b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8))
>b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12))
>[2, 3, 4] : [number, number, number]
>2 : number
>3 : number
>4 : number
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
>b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5))
>b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8))
>b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12))
>[1, 2, "string"] : [number, number, string]
>1 : number
>2 : number
>"string" : string
function foo() {
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
return [1, 2, 3];
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
}
var [b6, b7] = foo();
>b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5))
>b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8))
>foo() : number[]
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
var [...b8] = foo();
>b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5))
>foo() : number[]
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62))
// 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[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3))
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
var [c0, c1] = [...temp];
>c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5))
>c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8))
>[...temp] : number[]
>...temp : number
>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3))
var [c2] = [];
>c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5))
>[] : undefined[]
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
>c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7))
>c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17))
>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]]
>[[]] : [undefined[]]
>[] : undefined[]
>[[[[]]]] : [[[undefined[]]]]
>[[[]]] : [[undefined[]]]
>[[]] : [undefined[]]
>[] : undefined[]
var [[c5], c6]: [[string|number], boolean] = [[1], true];
>c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6))
>c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10))
>[[1], true] : [[number], boolean]
>[1] : [number]
>1 : number
>true : boolean
var [, c7] = [1, 2, 3];
> : undefined
>c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6))
>[1, 2, 3] : [number, number, number]
>1 : number
>2 : number
>3 : number
var [,,, c8] = [1, 2, 3, 4];
> : undefined
> : undefined
> : undefined
>c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8))
>[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, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8))
>[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)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8))
>[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, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5))
>c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9))
>c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14))
>[1, 2, "string"] : (string | number)[]
>1 : number
>2 : number
>"string" : string
var [c14, c15, c16] = [1, 2, "string"];
>c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5))
>c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9))
>c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14))
>[1, 2, "string"] : [number, number, string]
>1 : number
>2 : number
>"string" : string

View file

@ -0,0 +1,99 @@
//// [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;
var [a2 = false, a3 = 1]: any = 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];
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
function foo() {
return [1, 2, 3];
}
var [b6, b7] = foo();
var [...b8] = foo();
// 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]
var [c0, c1] = [...temp];
var [c2] = [];
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
var [[c5], c6]: [[string|number], boolean] = [[1], true];
var [, c7] = [1, 2, 3];
var [,,, c8] = [1, 2, 3, 4];
var [,,, c9] = [1, 2, 3, 4];
var [,,,...c10] = [1, 2, 3, 4, "hello"];
var [c11, c12, ...c13] = [1, 2, "string"];
var [c14, c15, c16] = [1, 2, "string"];
//// [destructuringArrayBindingPatternAndAssignment1ES6.js]
/* 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] = undefined;
var [a2 = false, a3 = 1] = 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];
var [b3, b4, b5] = [1, 2, "string"];
function foo() {
return [1, 2, 3];
}
var [b6, b7] = foo();
var [...b8] = foo();
// 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];
var [c0, c1] = [...temp];
var [c2] = [];
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]];
var [[c5], c6] = [[1], true];
var [, c7] = [1, 2, 3];
var [, , , c8] = [1, 2, 3, 4];
var [, , , c9] = [1, 2, 3, 4];
var [, , , ...c10] = [1, 2, 3, 4, "hello"];
var [c11, c12, ...c13] = [1, 2, "string"];
var [c14, c15, c16] = [1, 2, "string"];

View file

@ -0,0 +1,177 @@
=== 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, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5))
>a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8))
>undefined : undefined, Symbol(undefined)
var [a2 = false, a3 = 1]: any = undefined;
>a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5))
>false : boolean
>a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16))
>1 : number
>undefined : undefined, Symbol(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, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5))
>b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8))
>b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12))
>[2, 3, 4] : [number, number, number]
>2 : number
>3 : number
>4 : number
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
>b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5))
>b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8))
>b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12))
>[1, 2, "string"] : [number, number, string]
>1 : number
>2 : number
>"string" : string
function foo() {
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62))
return [1, 2, 3];
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
}
var [b6, b7] = foo();
>b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5))
>b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8))
>foo() : number[]
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62))
var [...b8] = foo();
>b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5))
>foo() : number[]
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62))
// 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[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3))
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
var [c0, c1] = [...temp];
>c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5))
>c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8))
>[...temp] : number[]
>...temp : number
>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3))
var [c2] = [];
>c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5))
>[] : undefined[]
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
>c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7))
>c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17))
>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]]
>[[]] : [undefined[]]
>[] : undefined[]
>[[[[]]]] : [[[undefined[]]]]
>[[[]]] : [[undefined[]]]
>[[]] : [undefined[]]
>[] : undefined[]
var [[c5], c6]: [[string|number], boolean] = [[1], true];
>c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6))
>c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10))
>[[1], true] : [[number], boolean]
>[1] : [number]
>1 : number
>true : boolean
var [, c7] = [1, 2, 3];
> : undefined
>c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6))
>[1, 2, 3] : [number, number, number]
>1 : number
>2 : number
>3 : number
var [,,, c8] = [1, 2, 3, 4];
> : undefined
> : undefined
> : undefined
>c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8))
>[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, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8))
>[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)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8))
>[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, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5))
>c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9))
>c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14))
>[1, 2, "string"] : (string | number)[]
>1 : number
>2 : number
>"string" : string
var [c14, c15, c16] = [1, 2, "string"];
>c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5))
>c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9))
>c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14))
>[1, 2, "string"] : [number, number, string]
>1 : number
>2 : number
>"string" : string

View file

@ -0,0 +1,71 @@
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'.
Types of property '1' are incompatible.
Type 'number' is not assignable to type 'boolean'.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(17,6): error TS2322: Type 'string' is not assignable to type 'Number'.
Property 'toFixed' is missing in type 'String'.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(22,5): error TS2322: Type 'number[]' is not assignable to type '[number, number]'.
Property '0' is missing in type 'number[]'.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(23,5): error TS2322: Type 'number[]' is not assignable to type '[string, string]'.
Property '0' is missing in type 'number[]'.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type.
==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (8 errors) ====
// 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]]] = [] // Error
~~~~
!!! error TS2461: Type 'undefined' is not an array type.
~~~~~~
!!! error TS2461: Type 'undefined' is not an array type.
var [[a2], [[a3]]] = undefined // Error
~~~~~~~~~~~~~~
!!! error TS2461: Type 'undefined' is not an array type.
// 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]: [number, boolean, string] = [1, 2, "string"]; // Error
~~~~~~~~~~~~
!!! error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'.
!!! error TS2322: Types of property '1' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'boolean'.
interface J extends Array<Number> {
2: number;
}
function bar(): J {
return <[number, number, number]>[1, 2, 3];
}
var [b3 = "string", b4, b5] = bar(); // Error
~~
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
!!! error TS2322: Property 'toFixed' is missing in type 'String'.
// 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 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]
var [c0, c1]: [number, number] = [...temp]; // Error
~~~~~~~~
!!! error TS2322: Type 'number[]' is not assignable to type '[number, number]'.
!!! error TS2322: Property '0' is missing in type 'number[]'.
var [c2, c3]: [string, string] = [...temp]; // Error
~~~~~~~~
!!! error TS2322: Type 'number[]' is not assignable to type '[string, string]'.
!!! error TS2322: Property '0' is missing in type 'number[]'.
interface F {
[idx: number]: boolean
}
function foo(idx: number): F {
return {
2: true
}
}
var [c4, c5, c6] = foo(1); // Error
~~~~~~~~~~~~
!!! error TS2461: Type 'F' is not an array type.

View file

@ -1,25 +1,60 @@
//// [destructuringArrayBindingPatternAndAssignment2.ts]
function foo() {
return [1, 2, 3];
}
// 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]]] = [] // Error
var [[a2], [[a3]]] = undefined // Error
// 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]: [number, boolean, string] = [1, 2, "string"]; // Error
interface J extends Array<Number> {
2: number;
}
function bar(): J {
return <[number, number, number]>[1, 2, 3];
return <[number, number, number]>[1, 2, 3];
}
var [b3 = "string", b4, b5] = bar(); // Error
// 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 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]
var [c0, c1]: [number, number] = [...temp]; // Error
var [c2, c3]: [string, string] = [...temp]; // Error
interface F {
[idx: number]: boolean
}
var [j, k] = foo();
var [...p] = foo();
function foo(idx: number): F {
return {
2: true
}
}
var [c4, c5, c6] = foo(1); // Error
//// [destructuringArrayBindingPatternAndAssignment2.js]
function foo() {
return [1, 2, 3];
}
// 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 _a = [], a0 = _a[0][0], a1 = _a[1][0][0]; // Error
var a2 = undefined[0][0], a3 = undefined[1][0][0]; // Error
// 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 _b = [1, 2, "string"], b0 = _b[0], b1 = _b[1], b2 = _b[2]; // Error
function bar() {
return [1, 2, 3];
}
var _a = foo(), j = _a[0], k = _a[1];
var _b = foo(), p = _b.slice(0);
var _c = bar(), _d = _c[0], b3 = _d === void 0 ? "string" : _d, b4 = _c[1], b5 = _c[2]; // Error
// 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 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];
var _e = temp, c0 = _e[0], c1 = _e[1]; // Error
var _f = temp, c2 = _f[0], c3 = _f[1]; // Error
function foo(idx) {
return {
2: true
};
}
var _g = foo(1), c4 = _g[0], c5 = _g[1], c6 = _g[2]; // Error

View file

@ -1,41 +0,0 @@
=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts ===
function foo() {
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0))
return [1, 2, 3];
>[1, 2, 3] : number[]
>1 : number
>2 : number
>3 : number
}
interface J extends Array<Number> {
>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1))
>Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
2: number;
}
function bar(): J {
>bar : () => J, Symbol(bar, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 5, 1))
>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1))
return <[number, number, number]>[1, 2, 3];
><[number, number, number]>[1, 2, 3] : [number, number, number]
>[1, 2, 3] : [number, number, number]
>1 : number
>2 : number
>3 : number
}
var [j, k] = foo();
>j : number, Symbol(j, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 5))
>k : number, Symbol(k, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 7))
>foo() : number[]
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0))
var [...p] = foo();
>p : number[], Symbol(p, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 12, 5))
>foo() : number[]
>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0))

View file

@ -1,51 +0,0 @@
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2322: Type 'undefined[]' is not assignable to type 'H'.
Property '0' is missing in type 'undefined[]'.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2461: Type 'H' is not an array type.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,6): error TS2461: Type 'undefined' is not an array type.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,13): error TS2461: Type 'undefined' is not an array type.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(21,13): error TS2462: A rest element must be last in an array destructuring pattern
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(22,6): error TS2322: Type 'string' is not assignable to type 'Number'.
Property 'toFixed' is missing in type 'String'.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(23,5): error TS2461: Type '{}' is not an array type.
==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts (7 errors) ====
interface H {
0: number,
1: string
}
interface J extends Array<Number> {
2: number;
}
function bar(): J {
return <[number, number, number]>[1, 2, 3];
}
function gg(idx: number) {
return {
[idx]: true
}
}
var [h, g, i]: H = [];
~~~~~~~~~
!!! error TS2322: Type 'undefined[]' is not assignable to type 'H'.
!!! error TS2322: Property '0' is missing in type 'undefined[]'.
~~~~~~~~~
!!! error TS2461: Type 'H' is not an array type.
var [[[y]], [[[[z]]]]] = []
~~~~~
!!! error TS2461: Type 'undefined' is not an array type.
~~~~~~~~~
!!! error TS2461: Type 'undefined' is not an array type.
var [, , ...w4, , ] = []
~~
!!! error TS2462: A rest element must be last in an array destructuring pattern
var [a = "string", b, c] = bar();
~
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
!!! error TS2322: Property 'toFixed' is missing in type 'String'.
var [r, s, t] = gg(1);
~~~~~~~~~
!!! error TS2461: Type '{}' is not an array type.

View file

@ -1,41 +0,0 @@
//// [destructuringArrayBindingPatternAndAssignment3.ts]
interface H {
0: number,
1: string
}
interface J extends Array<Number> {
2: number;
}
function bar(): J {
return <[number, number, number]>[1, 2, 3];
}
function gg(idx: number) {
return {
[idx]: true
}
}
var [h, g, i]: H = [];
var [[[y]], [[[[z]]]]] = []
var [, , ...w4, , ] = []
var [a = "string", b, c] = bar();
var [r, s, t] = gg(1);
//// [destructuringArrayBindingPatternAndAssignment3.js]
function bar() {
return [1, 2, 3];
}
function gg(idx) {
return (_a = {},
_a[idx] = true,
_a
);
var _a;
}
var _a = [], h = _a[0], g = _a[1], i = _a[2];
var _b = [], y = _b[0][0][0], z = _b[1][0][0][0][0];
var _c = [];
var _d = bar(), _e = _d[0], a = _e === void 0 ? "string" : _e, b = _d[1], c = _d[2];
var _f = gg(1), r = _f[0], s = _f[1], t = _f[2];

View file

@ -1,27 +0,0 @@
//// [destructuringObjectBindingPatternAndAssignment1.ts]
var c = 0;
var { a, } = { a:1, };
var { b: { c } } = { b: { c } };
var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } };
var { d1 }: any = undefined;
var { e1 }: any = {};
var { f: {f1} = { f1: "string" } }: any = {};
var { f2: {f21} = { f21: "string" } }: any = undefined;
var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined;
var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {};
var {g = 1}: any = { g: 100000 };
var {1: x} = { 1: "string" };
//// [destructuringObjectBindingPatternAndAssignment1.js]
var c = 0;
var a = ({ a: 1 }).a;
var c = ({ b: { c: c } }).b.c;
var _a = ({ b1: { c1: "world" } }).b1, c1 = (_a === void 0 ? { c1: "string" } : _a).c1;
var d1 = undefined.d1;
var e1 = ({}).e1;
var _b = ({}).f, f1 = (_b === void 0 ? { f1: "string" } : _b).f1;
var _c = undefined.f2, f21 = (_c === void 0 ? { f21: "string" } : _c).f21;
var _d = undefined.e1, e2 = (_d === void 0 ? { e2: "string" } : _d).e2;
var _e = ({}).e2, e3 = (_e === void 0 ? { e3: "string" } : _e).e3;
var _f = ({ g: 100000 }).g, g = _f === void 0 ? 1 : _f;
var x = ({ 1: "string" })[1];

View file

@ -1,87 +0,0 @@
=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts ===
var c = 0;
>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10))
>0 : number
var { a, } = { a:1, };
>a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 5))
>{ a:1, } : { a: number; }
>a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 14))
>1 : number
var { b: { c } } = { b: { c } };
>b : any
>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10))
>{ b: { c } } : { b: { c: number; }; }
>b : { c: number; }, Symbol(b, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 21))
>{ c } : { c: number; }
>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 26))
var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } };
>b1 : any
>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 11))
>{ c1: "string" } : { c1: string; }
>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 20))
>"string" : string
>{ b1: { c1: "world" } } : { b1: { c1: string; }; }
>b1 : { c1: string; }, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 42))
>{ c1: "world" } : { c1: string; }
>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 48))
>"world" : string
var { d1 }: any = undefined;
>d1 : any, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 4, 5))
>undefined : undefined, Symbol(undefined)
var { e1 }: any = {};
>e1 : any, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 5, 5))
>{} : {}
var { f: {f1} = { f1: "string" } }: any = {};
>f : any
>f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 10))
>{ f1: "string" } : { f1: string; }
>f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 17))
>"string" : string
>{} : {}
var { f2: {f21} = { f21: "string" } }: any = undefined;
>f2 : any
>f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 11))
>{ f21: "string" } : { f21: string; }
>f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 19))
>"string" : string
>undefined : undefined, Symbol(undefined)
var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined;
>e1 : any
>e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 11))
>{ e2: "string" } : { e2: string; }
>e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 18))
>"string" : string
>e1 : { e2: any; }, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 42))
>e2 : any, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 48))
>undefined : undefined, Symbol(undefined)
var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {};
>e2 : any
>e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 11))
>{ e3: "string" } : { e3: string; }
>e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 18))
>"string" : string
>e2 : { e3: any; }, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 42))
>e3 : any, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 48))
>{} : {}
var {g = 1}: any = { g: 100000 };
>g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 5))
>1 : number
>{ g: 100000 } : { g: number; }
>g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 20))
>100000 : number
var {1: x} = { 1: "string" };
>x : string, Symbol(x, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 11, 5))
>{ 1: "string" } : { 1: string; }
>"string" : string

View file

@ -0,0 +1,90 @@
//// [destructuringObjectBindingPatternAndAssignment1ES5.ts]
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 }: any = undefined;
var { a2 }: any = {};
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1:1, };
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
var {1: b3} = { 1: "string" };
var {b4 = 1}: any = { b4: 100000 };
var {b5: { b52 } } = { b5: { b52 } };
// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
// of a type that is assignable to the target given in P, or
interface F {
[idx: number]: boolean;
}
function foo(): F {
return {
1: true
};
}
function bar(): F {
return {
2: true
};
}
var {1: c0} = foo();
var {1: c1} = bar();
// V is an object assignment pattern and, for each assignment property P in V,
// S has a string index signature of a type that is assignable to the target given in P
interface F1 {
[str: string]: number;
}
function foo1(): F1 {
return {
"prop1": 2
}
}
var {"prop1": d1} = foo1();
var {"prop2": d1} = foo1();
//// [destructuringObjectBindingPatternAndAssignment1ES5.js]
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var a1 = undefined.a1;
var a2 = ({}).a2;
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var b1 = ({ b1: 1 }).b1;
var _a = ({ b2: { b21: "world" } }).b2, b21 = (_a === void 0 ? { b21: "string" } : _a).b21;
var b3 = ({ 1: "string" })[1];
var _b = ({ b4: 100000 }).b4, b4 = _b === void 0 ? 1 : _b;
var b52 = ({ b5: { b52: b52 } }).b5.b52;
function foo() {
return {
1: true
};
}
function bar() {
return {
2: true
};
}
var c0 = (foo())[1];
var c1 = (bar())[1];
function foo1() {
return {
"prop1": 2
};
}
var d1 = (foo1())["prop1"];
var d1 = (foo1())["prop2"];

View file

@ -0,0 +1,133 @@
=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts ===
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 }: any = undefined;
>a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5))
>undefined : undefined, Symbol(undefined)
var { a2 }: any = {};
>a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 6, 5))
>{} : {}
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1:1, };
>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5))
>{ b1:1, } : { b1: number; }
>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15))
>1 : number
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
>b2 : any
>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11))
>{ b21: "string" } : { b21: string; }
>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21))
>"string" : string
>{ b2: { b21: "world" } } : { b2: { b21: string; }; }
>b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44))
>{ b21: "world" } : { b21: string; }
>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50))
>"world" : string
var {1: b3} = { 1: "string" };
>b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5))
>{ 1: "string" } : { 1: string; }
>"string" : string
var {b4 = 1}: any = { b4: 100000 };
>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5))
>1 : number
>{ b4: 100000 } : { b4: number; }
>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21))
>100000 : number
var {b5: { b52 } } = { b5: { b52 } };
>b5 : any
>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10))
>{ b5: { b52 } } : { b5: { b52: any; }; }
>b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23))
>{ b52 } : { b52: any; }
>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29))
// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
// of a type that is assignable to the target given in P, or
interface F {
>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38))
[idx: number]: boolean;
>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5))
}
function foo(): F {
>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1))
>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38))
return {
>{ 1: true } : { [x: number]: boolean; 1: boolean; }
1: true
>true : boolean
};
}
function bar(): F {
>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1))
>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38))
return {
>{ 2: true } : { [x: number]: boolean; 2: boolean; }
2: true
>true : boolean
};
}
var {1: c0} = foo();
>c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5))
>foo() : F
>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1))
var {1: c1} = bar();
>c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5))
>bar() : F
>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1))
// V is an object assignment pattern and, for each assignment property P in V,
// S has a string index signature of a type that is assignable to the target given in P
interface F1 {
>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20))
[str: string]: number;
>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5))
}
function foo1(): F1 {
>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1))
>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20))
return {
>{ "prop1": 2 } : { [x: string]: number; "prop1": number; }
"prop1": 2
>2 : number
}
}
var {"prop1": d1} = foo1();
>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5))
>foo1() : F1
>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1))
var {"prop2": d1} = foo1();
>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5))
>foo1() : F1
>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1))

View file

@ -0,0 +1,90 @@
//// [destructuringObjectBindingPatternAndAssignment1ES6.ts]
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 }: any = undefined;
var { a2 }: any = {};
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1:1, };
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
var {1: b3} = { 1: "string" };
var {b4 = 1}: any = { b4: 100000 };
var {b5: { b52 } } = { b5: { b52 } };
// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
// of a type that is assignable to the target given in P, or
interface F {
[idx: number]: boolean;
}
function foo(): F {
return {
1: true
};
}
function bar(): F {
return {
2: true
};
}
var {1: c0} = foo();
var {1: c1} = bar();
// V is an object assignment pattern and, for each assignment property P in V,
// S has a string index signature of a type that is assignable to the target given in P
interface F1 {
[str: string]: number;
}
function foo1(): F1 {
return {
"prop1": 2
}
}
var {"prop1": d1} = foo1();
var {"prop2": d1} = foo1();
//// [destructuringObjectBindingPatternAndAssignment1ES6.js]
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 } = undefined;
var { a2 } = {};
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1: 1, };
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
var { 1: b3 } = { 1: "string" };
var { b4 = 1 } = { b4: 100000 };
var { b5: { b52 } } = { b5: { b52 } };
function foo() {
return {
1: true
};
}
function bar() {
return {
2: true
};
}
var { 1: c0 } = foo();
var { 1: c1 } = bar();
function foo1() {
return {
"prop1": 2
};
}
var { "prop1": d1 } = foo1();
var { "prop2": d1 } = foo1();

View file

@ -0,0 +1,133 @@
=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts ===
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 }: any = undefined;
>a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5))
>undefined : undefined, Symbol(undefined)
var { a2 }: any = {};
>a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5))
>{} : {}
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1:1, };
>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5))
>{ b1:1, } : { b1: number; }
>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15))
>1 : number
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
>b2 : any
>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11))
>{ b21: "string" } : { b21: string; }
>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21))
>"string" : string
>{ b2: { b21: "world" } } : { b2: { b21: string; }; }
>b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44))
>{ b21: "world" } : { b21: string; }
>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50))
>"world" : string
var {1: b3} = { 1: "string" };
>b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5))
>{ 1: "string" } : { 1: string; }
>"string" : string
var {b4 = 1}: any = { b4: 100000 };
>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5))
>1 : number
>{ b4: 100000 } : { b4: number; }
>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21))
>100000 : number
var {b5: { b52 } } = { b5: { b52 } };
>b5 : any
>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10))
>{ b5: { b52 } } : { b5: { b52: any; }; }
>b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23))
>{ b52 } : { b52: any; }
>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29))
// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
// of a type that is assignable to the target given in P, or
interface F {
>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38))
[idx: number]: boolean;
>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5))
}
function foo(): F {
>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1))
>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38))
return {
>{ 1: true } : { [x: number]: boolean; 1: boolean; }
1: true
>true : boolean
};
}
function bar(): F {
>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1))
>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38))
return {
>{ 2: true } : { [x: number]: boolean; 2: boolean; }
2: true
>true : boolean
};
}
var {1: c0} = foo();
>c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5))
>foo() : F
>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1))
var {1: c1} = bar();
>c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5))
>bar() : F
>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1))
// V is an object assignment pattern and, for each assignment property P in V,
// S has a string index signature of a type that is assignable to the target given in P
interface F1 {
>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20))
[str: string]: number;
>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5))
}
function foo1(): F1 {
>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1))
>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20))
return {
>{ "prop1": 2 } : { [x: string]: number; "prop1": number; }
"prop1": 2
>2 : number
}
}
var {"prop1": d1} = foo1();
>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5))
>foo1() : F1
>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1))
var {"prop2": d1} = foo1();
>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5))
>foo1() : F1
>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1))

View file

@ -1,76 +0,0 @@
//// [destructuringObjectBindingPatternAndAssignment2.ts]
interface I {
j: number;
[str: string]: number;
}
interface J {
[str: string]: number;
}
function zz() {
return {
"cat": "dog",
}
}
function zz1(): J {
return {
"cat": 1,
}
}
function yy() {
return {}
}
var {j}: I| J = { j: 1000 };
var {cat} = zz();
var {"cat":cart} = zz();
var {can}: J = {};
var {can1}: J = zz1();
function f() {
var { z }: { z: number } = { z };
}
interface K {
[idx: number]: boolean
}
var {1: boo}: K = { 1: true };
var {1: boo1}: K = { };
function bar(): K {
return { };
}
var {1: baz} = bar();
//// [destructuringObjectBindingPatternAndAssignment2.js]
function zz() {
return {
"cat": "dog"
};
}
function zz1() {
return {
"cat": 1
};
}
function yy() {
return {};
}
var j = ({ j: 1000 }).j;
var cat = (zz()).cat;
var cart = (zz())["cat"];
var can = ({}).can;
var can1 = (zz1()).can1;
function f() {
var z = ({ z: z }).z;
}
var boo = ({ 1: true })[1];
var boo1 = ({})[1];
function bar() {
return {};
}
var baz = (bar())[1];

View file

@ -1,116 +0,0 @@
=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts ===
interface I {
>I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0))
j: number;
>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 13))
[str: string]: number;
>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 2, 5))
}
interface J {
>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1))
[str: string]: number;
>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 5, 5))
}
function zz() {
>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1))
return {
>{ "cat": "dog", } : { "cat": string; }
"cat": "dog",
>"dog" : string
}
}
function zz1(): J {
>zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1))
>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1))
return {
>{ "cat": 1, } : { [x: string]: number; "cat": number; }
"cat": 1,
>1 : number
}
}
function yy() {
>yy : () => {}, Symbol(yy, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 17, 1))
return {}
>{} : {}
}
var {j}: I| J = { j: 1000 };
>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 5))
>I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0))
>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1))
>{ j: 1000 } : { [x: string]: number; j: number; }
>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 17))
>1000 : number
var {cat} = zz();
>cat : string, Symbol(cat, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 24, 5))
>zz() : { "cat": string; }
>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1))
var {"cat":cart} = zz();
>cart : string, Symbol(cart, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 25, 5))
>zz() : { "cat": string; }
>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1))
var {can}: J = {};
>can : number, Symbol(can, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 27, 5))
>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1))
>{} : { [x: string]: undefined; }
var {can1}: J = zz1();
>can1 : number, Symbol(can1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 5))
>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1))
>zz1() : J
>zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1))
function f() {
>f : () => void, Symbol(f, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 22))
var { z }: { z: number } = { z };
>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 9))
>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 16))
>{ z } : { z: number; }
>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 32))
}
interface K {
>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1))
[idx: number]: boolean
>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 36, 5))
}
var {1: boo}: K = { 1: true };
>boo : boolean, Symbol(boo, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 39, 5))
>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1))
>{ 1: true } : { [x: number]: boolean; 1: boolean; }
>true : boolean
var {1: boo1}: K = { };
>boo1 : boolean, Symbol(boo1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 5))
>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1))
>{ } : { [x: number]: undefined; }
function bar(): K {
>bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23))
>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1))
return { };
>{ } : { [x: number]: undefined; }
}
var {1: baz} = bar();
>baz : boolean, Symbol(baz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 45, 5))
>bar() : K
>bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23))

View file

@ -1,16 +1,17 @@
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(1,7): error TS1005: ',' expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,7): error TS1005: ',' expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'.
Type '{ i: number; }' is not assignable to type 'number'.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,54): error TS2304: Cannot find name 'c'.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,7): error TS1180: Property destructuring pattern expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,7): error TS1005: ':' expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,15): error TS1005: ':' expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,7): error TS1005: ':' expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,15): error TS1005: ':' expected.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,12): error TS1005: ':' expected.
==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ====
// Error
var {h?} = { h?: 1 };
~
!!! error TS1005: ',' expected.
@ -26,10 +27,6 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs
var { f2: {f21} = { f212: "string" } }: any = undefined;
~~~
!!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature.
var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } };
~
!!! error TS2304: Cannot find name 'c'.
var { d }: any;
var { ...d1 } = {
~~~
!!! error TS1180: Property destructuring pattern expected.
@ -39,4 +36,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs
~
!!! error TS1005: ':' expected.
~
!!! error TS1005: ':' expected.
var {"prop"} = { "prop": 1 };
~
!!! error TS1005: ':' expected.

View file

@ -1,23 +1,23 @@
//// [destructuringObjectBindingPatternAndAssignment3.ts]
// Error
var {h?} = { h?: 1 };
var {i}: string | number = { i: 2 };
var {i1}: string | number| {} = { i1: 2 };
var { f2: {f21} = { f212: "string" } }: any = undefined;
var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } };
var { d }: any;
var { ...d1 } = {
a: 1, b: 1, d1: 9, e: 10
}
var {1} = { 1 };
var {1} = { 1 };
var {"prop"} = { "prop": 1 };
//// [destructuringObjectBindingPatternAndAssignment3.js]
// Error
var h = ({ h: 1 }).h;
var i = ({ i: 2 }).i;
var i1 = ({ i1: 2 }).i1;
var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21;
var _b = ({ b1: { c1: c } }).b1, c1 = (_b === void 0 ? { c1: "string" } : _b).c1;
var d = (void 0).d;
var d1 = ({
a: 1, b: 1, d1: 9, e: 10
}).d1;
var = ({ 1: })[1];
var = ({ "prop": 1 })["prop"];

View file

@ -1,37 +0,0 @@
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(7,6): error TS2459: Type 'K | K1' has no property 'k' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(12,6): error TS2459: Type '{}' has no property '2' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(23,5): error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'.
Index signature is missing in type '{ "cat": string; }'.
==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts (3 errors) ====
interface K {
[str: string]: string;
}
interface K1 {
k: string;
}
var {k}: K|K1 = { k: "string" };
~
!!! error TS2459: Type 'K | K1' has no property 'k' and no string index signature.
function barn() {
return {};
}
var {2: baz1} = barn()
~
!!! error TS2459: Type '{}' has no property '2' and no string index signature.
interface J {
[str: string]: number;
}
function zz() {
return {
"cat": "dog"
}
}
var {"can": can}: J = zz();
~~~~~~~~~~~~
!!! error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'.
!!! error TS2322: Index signature is missing in type '{ "cat": string; }'.

View file

@ -1,37 +0,0 @@
//// [destructuringObjectBindingPatternAndAssignment4.ts]
interface K {
[str: string]: string;
}
interface K1 {
k: string;
}
var {k}: K|K1 = { k: "string" };
function barn() {
return {};
}
var {2: baz1} = barn()
interface J {
[str: string]: number;
}
function zz() {
return {
"cat": "dog"
}
}
var {"can": can}: J = zz();
//// [destructuringObjectBindingPatternAndAssignment4.js]
var k = ({ k: "string" }).k;
function barn() {
return {};
}
var baz1 = (barn())[2];
function zz() {
return {
"cat": "dog"
};
}
var can = (zz())["can"];

View file

@ -0,0 +1,77 @@
//// [destructuringVariableDeclaration1ES5.ts]
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" }
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true];
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } };
var temp = { t1: true, t2: "false" };
var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [...c1] = [1,2,3];
var [...c2] = [1,2,3, "string"];
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var [d1,d2] = [1,"string"]
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true]
var [d3, d4] = [1, "string", ...temp1];
// Combining both forms of destructuring,
var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] };
var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] };
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } };
var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } };
//// [destructuringVariableDeclaration1ES5.js]
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var _a = { a1: 10, a2: "world" }, a1 = _a.a1, a2 = _a.a2;
var _b = [1, [["hello"]], true], a3 = _b[0], a4 = _b[1][0][0], a5 = _b[2];
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var _c = ({ b1: { b11: "world" } }).b1, b11 = (_c === void 0 ? { b11: "string" } : _c).b11;
var temp = { t1: true, t2: "false" };
var _d = [3, false, { t1: false, t2: "hello" }], _e = _d[0], b2 = _e === void 0 ? 3 : _e, _f = _d[1], b3 = _f === void 0 ? true : _f, _g = _d[2], b4 = _g === void 0 ? temp : _g;
var _h = [undefined, undefined, undefined], _j = _h[0], b5 = _j === void 0 ? 3 : _j, _k = _h[1], b6 = _k === void 0 ? true : _k, _l = _h[2], b7 = _l === void 0 ? temp : _l;
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var _m = [1, 2, 3], c1 = _m.slice(0);
var _o = [1, 2, 3, "string"], c2 = _o.slice(0);
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var _p = [1, "string"], d1 = _p[0], d2 = _p[1];
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true];
var _q = [1, "string"].concat(temp1), d3 = _q[0], d4 = _q[1];
// Combining both forms of destructuring,
var _r = ({ e: [1, 2, { b1: 4, b4: 0 }] }).e, e1 = _r[0], e2 = _r[1], _s = _r[2], e3 = _s === void 0 ? { b1: 1000, b4: 200 } : _s;
var _t = ({ f: [1, 2, { f3: 4, f5: 0 }] }).f, f1 = _t[0], f2 = _t[1], _u = _t[2], f4 = _u.f3, f5 = _u.f5;
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var _v = ({ g: { g1: [1, 2] } }).g.g1, g1 = _v === void 0 ? [undefined, null] : _v;
var _w = ({ h: { h1: [1, 2] } }).h.h1, h1 = _w === void 0 ? [undefined, null] : _w;

View file

@ -0,0 +1,200 @@
=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts ===
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" }
>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 5))
>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8))
>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15))
>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27))
>{ a1: 10, a2: "world" } : { a1: number; a2: string; }
>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44))
>10 : number
>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52))
>"world" : string
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true];
>a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5))
>a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11))
>a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES5.ts, 3, 16))
>[1, [["hello"]], true] : [number, [[string]], boolean]
>1 : number
>[["hello"]] : [[string]]
>["hello"] : [string]
>"hello" : string
>true : boolean
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } };
>b1 : any
>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11))
>{ b11: "string" } : { b11: string; }
>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21))
>"string" : string
>{ b1: { b11: "world" } } : { b1: { b11: string; }; }
>b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44))
>{ b11: "world" } : { b11: string; }
>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50))
>"world" : string
var temp = { t1: true, t2: "false" };
>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3))
>{ t1: true, t2: "false" } : { t1: boolean; t2: string; }
>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12))
>true : boolean
>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22))
>"false" : string
var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5))
>3 : number
>b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12))
>true : boolean
>b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23))
>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3))
>[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }]
>3 : number
>false : boolean
>{ t1: false, t2: "hello" } : { t1: boolean; t2: string; }
>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49))
>false : boolean
>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60))
>"hello" : string
var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
>b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5))
>3 : number
>b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12))
>true : boolean
>b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23))
>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3))
>[undefined, undefined, undefined] : [undefined, undefined, undefined]
>undefined : undefined, Symbol(undefined)
>undefined : undefined, Symbol(undefined)
>undefined : undefined, Symbol(undefined)
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [...c1] = [1,2,3];
>c1 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES5.ts, 15, 5))
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
var [...c2] = [1,2,3, "string"];
>c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES5.ts, 16, 5))
>[1,2,3, "string"] : (string | number)[]
>1 : number
>2 : number
>3 : number
>"string" : string
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var [d1,d2] = [1,"string"]
>d1 : number, Symbol(d1, Decl(destructuringVariableDeclaration1ES5.ts, 22, 5))
>d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES5.ts, 22, 8))
>[1,"string"] : [number, string]
>1 : number
>"string" : string
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true]
>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3))
>[true, false, true] : boolean[]
>true : boolean
>false : boolean
>true : boolean
var [d3, d4] = [1, "string", ...temp1];
>d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5))
>d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8))
>[1, "string", ...temp1] : (string | number | boolean)[]
>1 : number
>"string" : string
>...temp1 : boolean
>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3))
// Combining both forms of destructuring,
var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] };
>e : any
>e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9))
>e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12))
>e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16))
>{ b1: 1000, b4: 200 } : { b1: number; b4: number; }
>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23))
>1000 : number
>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33))
>200 : number
>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; }
>e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49))
>[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }]
>1 : number
>2 : number
>{ b1: 4, b4: 0 } : { b1: number; b4: number; }
>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61))
>4 : number
>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68))
>0 : number
var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] };
>f : any
>f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9))
>f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12))
>f3 : any
>f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18))
>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26))
> : undefined
>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; }
>f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41))
>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }]
>1 : number
>2 : number
>{ f3: 4, f5: 0 } : { f3: number; f5: number; }
>f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53))
>4 : number
>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 60))
>0 : number
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } };
>g : any
>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9))
>[undefined, null] : null[]
>undefined : undefined, Symbol(undefined)
>null : null
>g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36))
>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41))
>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; }
>g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59))
>{ g1: [1, 2] } : { g1: number[]; }
>g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64))
>[1, 2] : number[]
>1 : number
>2 : number
var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } };
>h : any
>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9))
>[undefined, null] : null[]
>undefined : undefined, Symbol(undefined)
>null : null
>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36))
>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41))
>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; }
>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62))
>{ h1: [1, 2] } : { h1: number[]; }
>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67))
>[1, 2] : number[]
>1 : number
>2 : number

View file

@ -0,0 +1,77 @@
//// [destructuringVariableDeclaration1ES6.ts]
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" }
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true];
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } };
var temp = { t1: true, t2: "false" };
var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [...c1] = [1,2,3];
var [...c2] = [1,2,3, "string"];
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var [d1,d2] = [1,"string"]
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true]
var [d3, d4] = [1, "string", ...temp1];
// Combining both forms of destructuring,
var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] };
var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] };
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } };
var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } };
//// [destructuringVariableDeclaration1ES6.js]
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var { a1, a2 } = { a1: 10, a2: "world" };
var [a3, [[a4]], a5] = [1, [["hello"]], true];
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } };
var temp = { t1: true, t2: "false" };
var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [...c1] = [1, 2, 3];
var [...c2] = [1, 2, 3, "string"];
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var [d1, d2] = [1, "string"];
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true];
var [d3, d4] = [1, "string", ...temp1];
// Combining both forms of destructuring,
var { e: [e1, e2, e3 = { b1: 1000, b4: 200 }] } = { e: [1, 2, { b1: 4, b4: 0 }] };
var { f: [f1, f2, { f3: f4, f5 }, ,] } = { f: [1, 2, { f3: 4, f5: 0 }] };
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var { g: { g1 = [undefined, null] } } = { g: { g1: [1, 2] } };
var { h: { h1 = [undefined, null] } } = { h: { h1: [1, 2] } };

View file

@ -0,0 +1,200 @@
=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts ===
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" }
>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 5))
>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8))
>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15))
>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27))
>{ a1: 10, a2: "world" } : { a1: number; a2: string; }
>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44))
>10 : number
>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52))
>"world" : string
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true];
>a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5))
>a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11))
>a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES6.ts, 3, 16))
>[1, [["hello"]], true] : [number, [[string]], boolean]
>1 : number
>[["hello"]] : [[string]]
>["hello"] : [string]
>"hello" : string
>true : boolean
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } };
>b1 : any
>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11))
>{ b11: "string" } : { b11: string; }
>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21))
>"string" : string
>{ b1: { b11: "world" } } : { b1: { b11: string; }; }
>b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44))
>{ b11: "world" } : { b11: string; }
>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50))
>"world" : string
var temp = { t1: true, t2: "false" };
>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3))
>{ t1: true, t2: "false" } : { t1: boolean; t2: string; }
>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12))
>true : boolean
>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22))
>"false" : string
var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
>b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5))
>3 : number
>b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12))
>true : boolean
>b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23))
>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3))
>[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }]
>3 : number
>false : boolean
>{ t1: false, t2: "hello" } : { t1: boolean; t2: string; }
>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49))
>false : boolean
>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60))
>"hello" : string
var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
>b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5))
>3 : number
>b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12))
>true : boolean
>b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23))
>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3))
>[undefined, undefined, undefined] : [undefined, undefined, undefined]
>undefined : undefined, Symbol(undefined)
>undefined : undefined, Symbol(undefined)
>undefined : undefined, Symbol(undefined)
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [...c1] = [1,2,3];
>c1 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES6.ts, 15, 5))
>[1,2,3] : number[]
>1 : number
>2 : number
>3 : number
var [...c2] = [1,2,3, "string"];
>c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES6.ts, 16, 5))
>[1,2,3, "string"] : (string | number)[]
>1 : number
>2 : number
>3 : number
>"string" : string
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var [d1,d2] = [1,"string"]
>d1 : number, Symbol(d1, Decl(destructuringVariableDeclaration1ES6.ts, 22, 5))
>d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES6.ts, 22, 8))
>[1,"string"] : [number, string]
>1 : number
>"string" : string
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true]
>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3))
>[true, false, true] : boolean[]
>true : boolean
>false : boolean
>true : boolean
var [d3, d4] = [1, "string", ...temp1];
>d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5))
>d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8))
>[1, "string", ...temp1] : (string | number | boolean)[]
>1 : number
>"string" : string
>...temp1 : boolean
>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3))
// Combining both forms of destructuring,
var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] };
>e : any
>e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9))
>e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12))
>e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16))
>{ b1: 1000, b4: 200 } : { b1: number; b4: number; }
>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23))
>1000 : number
>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33))
>200 : number
>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; }
>e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49))
>[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }]
>1 : number
>2 : number
>{ b1: 4, b4: 0 } : { b1: number; b4: number; }
>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61))
>4 : number
>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68))
>0 : number
var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] };
>f : any
>f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9))
>f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12))
>f3 : any
>f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18))
>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26))
> : undefined
>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; }
>f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41))
>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }]
>1 : number
>2 : number
>{ f3: 4, f5: 0 } : { f3: number; f5: number; }
>f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53))
>4 : number
>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 60))
>0 : number
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } };
>g : any
>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9))
>[undefined, null] : null[]
>undefined : undefined, Symbol(undefined)
>null : null
>g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36))
>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41))
>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; }
>g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59))
>{ g1: [1, 2] } : { g1: number[]; }
>g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64))
>[1, 2] : number[]
>1 : number
>2 : number
var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } };
>h : any
>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9))
>[undefined, null] : null[]
>undefined : undefined, Symbol(undefined)
>null : null
>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36))
>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41))
>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; }
>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62))
>{ h1: [1, 2] } : { h1: number[]; }
>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67))
>[1, 2] : number[]
>1 : number
>2 : number

View file

@ -0,0 +1,62 @@
tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(3,5): error TS2322: Type '{ a1: boolean; a2: number; }' is not assignable to type '{ a1: number; a2: string; }'.
Types of property 'a1' are incompatible.
Type 'boolean' is not assignable to type 'number'.
tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(4,5): error TS2322: Type '[number, [[boolean]], boolean]' is not assignable to type '[number, [[string]], boolean]'.
Types of property '1' are incompatible.
Type '[[boolean]]' is not assignable to type '[[string]]'.
Types of property '0' are incompatible.
Type '[boolean]' is not assignable to type '[string]'.
Types of property '0' are incompatible.
Type 'boolean' is not assignable to type 'string'.
tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(9,25): error TS2322: Type '{ t1: boolean; t2: string; }' is not assignable to type '{ t1: boolean; t2: number; }'.
Types of property 't2' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,16): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,24): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(19,10): error TS2322: Type 'string[]' is not assignable to type 'number[]'.
Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts (6 errors) ====
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: true, a2: 1 } // Error
~~~~~~~~
!!! error TS2322: Type '{ a1: boolean; a2: number; }' is not assignable to type '{ a1: number; a2: string; }'.
!!! error TS2322: Types of property 'a1' are incompatible.
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error
~~~~~~~~~~~~~~~~
!!! error TS2322: Type '[number, [[boolean]], boolean]' is not assignable to type '[number, [[string]], boolean]'.
!!! error TS2322: Types of property '1' are incompatible.
!!! error TS2322: Type '[[boolean]]' is not assignable to type '[[string]]'.
!!! error TS2322: Types of property '0' are incompatible.
!!! error TS2322: Type '[boolean]' is not assignable to type '[string]'.
!!! error TS2322: Types of property '0' are incompatible.
!!! error TS2322: Type 'boolean' is not assignable to type 'string'.
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var temp = { t1: true, t2: "false" };
var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error
~~
!!! error TS2322: Type '{ t1: boolean; t2: string; }' is not assignable to type '{ t1: boolean; t2: number; }'.
!!! error TS2322: Types of property 't2' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error
~~
!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature.
~~
!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature.
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error
~~
!!! error TS2322: Type 'string[]' is not assignable to type 'number[]'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.

View file

@ -0,0 +1,38 @@
//// [destructuringVariableDeclaration2.ts]
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: true, a2: 1 } // Error
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var temp = { t1: true, t2: "false" };
var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error
//// [destructuringVariableDeclaration2.js]
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var _a = { a1: true, a2: 1 }, a1 = _a.a1, a2 = _a.a2; // Error
var _b = [1, [[false]], true], a3 = _b[0], a4 = _b[1][0][0], a5 = _b[2]; // Error
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var temp = { t1: true, t2: "false" };
var _c = [3, false, { t1: false, t2: 5 }], _d = _c[0], b0 = _d === void 0 ? 3 : _d, _e = _c[1], b1 = _e === void 0 ? true : _e, _f = _c[2], b2 = _f === void 0 ? temp : _f; // Error
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var _g = [1, 2, { c3: 4, c5: 0 }], c1 = _g[0], c2 = _g[1], _h = _g[2], c4 = _h.c3, c5 = _h.c5, c6 = _g.slice(4); // Error
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var _j = ({ d: { d1: [1, 2] } }).d.d1, d1 = _j === void 0 ? ["string", null] : _j; // Error

View file

@ -1,15 +0,0 @@
tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,23): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,33): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,44): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'.
==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts (3 errors) ====
var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] };
var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] };
var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] };
~~~
!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature.
~~~
!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature.
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'.

View file

@ -1,9 +0,0 @@
//// [destructuringVariableDeclarationAndAssignment.ts]
var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] };
var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] };
var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] };
//// [destructuringVariableDeclarationAndAssignment.js]
var _a = ({ o: [1, 2, { b1: 4, b4: 0 }] }).o, a1 = _a[0], a2 = _a[1], _b = _a[2], a3 = _b === void 0 ? { b1: 1000, b4: 200 } : _b;
var _c = ({ o0: [1, 2, { e: 4, f: 0 }] }).o0, c = _c[0], d = _c[1], _d = _c[2], e1 = _d.e, f = _d.f;
var _e = ({ o1: [1, 2, { b12: 4, b42: 0 }] }).o1, a11 = _e[0], a21 = _e[1], _f = _e[2], b22 = _f.b12, b42 = _f.b42, c = _e.slice(4);

View file

@ -1,22 +0,0 @@
var [p0,p1, p2] : any = [2, 3, 4];
var [a, b, c]: [number, number, string] = [1, 2, "string"];
var [d, e]: any = undefined;
var [f = false, g = 1]: any = undefined;
g = 10;
f = true;
var [x] = []
var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]]
var [[w], m]: [[string|number], boolean] = [[1], true];
interface J extends Array<Number> {
2: number;
}
var [, w1] = [1, 2, 3];
var [,,, w2] = [1, 2, 3, 4];
var [,,, w2] = [1, 2, 3, 4];
var [,,,...w3] = [1, 2, 3, 4, "hello"];
var [r, s, ...t] = [1, 2, "string"];
var [r1, s1, t1] = [1, 2, "string"];

View file

@ -0,0 +1,52 @@
/* 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;
var [a2 = false, a3 = 1]: any = 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];
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
function foo() {
return [1, 2, 3];
}
var [b6, b7] = foo();
var [...b8] = foo();
// 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]
var [c0, c1] = [...temp];
var [c2] = [];
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
var [[c5], c6]: [[string|number], boolean] = [[1], true];
var [, c7] = [1, 2, 3];
var [,,, c8] = [1, 2, 3, 4];
var [,,, c9] = [1, 2, 3, 4];
var [,,,...c10] = [1, 2, 3, 4, "hello"];
var [c11, c12, ...c13] = [1, 2, "string"];
var [c14, c15, c16] = [1, 2, "string"];

View file

@ -0,0 +1,53 @@
// @target: es6
/* 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;
var [a2 = false, a3 = 1]: any = 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];
var [b3, b4, b5]: [number, number, string] = [1, 2, "string"];
function foo() {
return [1, 2, 3];
}
var [b6, b7] = foo();
var [...b8] = foo();
// 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]
var [c0, c1] = [...temp];
var [c2] = [];
var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]
var [[c5], c6]: [[string|number], boolean] = [[1], true];
var [, c7] = [1, 2, 3];
var [,,, c8] = [1, 2, 3, 4];
var [,,, c9] = [1, 2, 3, 4];
var [,,,...c10] = [1, 2, 3, 4, "hello"];
var [c11, c12, ...c13] = [1, 2, "string"];
var [c14, c15, c16] = [1, 2, "string"];

View file

@ -1,13 +1,34 @@
function foo() {
return [1, 2, 3];
}
// 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]]] = [] // Error
var [[a2], [[a3]]] = undefined // Error
// 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]: [number, boolean, string] = [1, 2, "string"]; // Error
interface J extends Array<Number> {
2: number;
}
function bar(): J {
return <[number, number, number]>[1, 2, 3];
return <[number, number, number]>[1, 2, 3];
}
var [b3 = "string", b4, b5] = bar(); // Error
// 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 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]
var [c0, c1]: [number, number] = [...temp]; // Error
var [c2, c3]: [string, string] = [...temp]; // Error
interface F {
[idx: number]: boolean
}
var [j, k] = foo();
var [...p] = foo();
function foo(idx: number): F {
return {
2: true
}
}
var [c4, c5, c6] = foo(1); // Error

View file

@ -1,23 +0,0 @@
interface H {
0: number,
1: string
}
interface J extends Array<Number> {
2: number;
}
function bar(): J {
return <[number, number, number]>[1, 2, 3];
}
function gg(idx: number) {
return {
[idx]: true
}
}
var [h, g, i]: H = [];
var [[[y]], [[[[z]]]]] = []
var [, , ...w4, , ] = []
var [a = "string", b, c] = bar();
var [r, s, t] = gg(1);

View file

@ -1,12 +0,0 @@
var c = 0;
var { a, } = { a:1, };
var { b: { c } } = { b: { c } };
var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } };
var { d1 }: any = undefined;
var { e1 }: any = {};
var { f: {f1} = { f1: "string" } }: any = {};
var { f2: {f21} = { f21: "string" } }: any = undefined;
var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined;
var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {};
var {g = 1}: any = { g: 100000 };
var {1: x} = { 1: "string" };

View file

@ -0,0 +1,54 @@
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 }: any = undefined;
var { a2 }: any = {};
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1:1, };
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
var {1: b3} = { 1: "string" };
var {b4 = 1}: any = { b4: 100000 };
var {b5: { b52 } } = { b5: { b52 } };
// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
// of a type that is assignable to the target given in P, or
interface F {
[idx: number]: boolean;
}
function foo(): F {
return {
1: true
};
}
function bar(): F {
return {
2: true
};
}
var {1: c0} = foo();
var {1: c1} = bar();
// V is an object assignment pattern and, for each assignment property P in V,
// S has a string index signature of a type that is assignable to the target given in P
interface F1 {
[str: string]: number;
}
function foo1(): F1 {
return {
"prop1": 2
}
}
var {"prop1": d1} = foo1();
var {"prop2": d1} = foo1();

View file

@ -0,0 +1,55 @@
// @target: es6
// 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 object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 }: any = undefined;
var { a2 }: any = {};
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1:1, };
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
var {1: b3} = { 1: "string" };
var {b4 = 1}: any = { b4: 100000 };
var {b5: { b52 } } = { b5: { b52 } };
// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
// of a type that is assignable to the target given in P, or
interface F {
[idx: number]: boolean;
}
function foo(): F {
return {
1: true
};
}
function bar(): F {
return {
2: true
};
}
var {1: c0} = foo();
var {1: c1} = bar();
// V is an object assignment pattern and, for each assignment property P in V,
// S has a string index signature of a type that is assignable to the target given in P
interface F1 {
[str: string]: number;
}
function foo1(): F1 {
return {
"prop1": 2
}
}
var {"prop1": d1} = foo1();
var {"prop2": d1} = foo1();

View file

@ -1,46 +0,0 @@
interface I {
j: number;
[str: string]: number;
}
interface J {
[str: string]: number;
}
function zz() {
return {
"cat": "dog",
}
}
function zz1(): J {
return {
"cat": 1,
}
}
function yy() {
return {}
}
var {j}: I| J = { j: 1000 };
var {cat} = zz();
var {"cat":cart} = zz();
var {can}: J = {};
var {can1}: J = zz1();
function f() {
var { z }: { z: number } = { z };
}
interface K {
[idx: number]: boolean
}
var {1: boo}: K = { 1: true };
var {1: boo1}: K = { };
function bar(): K {
return { };
}
var {1: baz} = bar();

View file

@ -1,10 +1,10 @@
var {h?} = { h?: 1 };
// Error
var {h?} = { h?: 1 };
var {i}: string | number = { i: 2 };
var {i1}: string | number| {} = { i1: 2 };
var { f2: {f21} = { f212: "string" } }: any = undefined;
var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } };
var { d }: any;
var { ...d1 } = {
a: 1, b: 1, d1: 9, e: 10
}
var {1} = { 1 };
var {1} = { 1 };
var {"prop"} = { "prop": 1 };

View file

@ -1,23 +0,0 @@
interface K {
[str: string]: string;
}
interface K1 {
k: string;
}
var {k}: K|K1 = { k: "string" };
function barn() {
return {};
}
var {2: baz1} = barn()
interface J {
[str: string]: number;
}
function zz() {
return {
"cat": "dog"
}
}
var {"can": can}: J = zz();

View file

@ -0,0 +1,40 @@
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" }
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true];
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } };
var temp = { t1: true, t2: "false" };
var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [...c1] = [1,2,3];
var [...c2] = [1,2,3, "string"];
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var [d1,d2] = [1,"string"]
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true]
var [d3, d4] = [1, "string", ...temp1];
// Combining both forms of destructuring,
var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] };
var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] };
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } };
var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } };

View file

@ -0,0 +1,41 @@
// @target: es6
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" }
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true];
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } };
var temp = { t1: true, t2: "false" };
var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }];
var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined];
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [...c1] = [1,2,3];
var [...c2] = [1,2,3, "string"];
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Let N be the zero-based index of the binding element in the array binding pattern.
// If S has a property with the numerical name N, T is the type of that property.
var [d1,d2] = [1,"string"]
// The type T associated with a binding element is determined as follows:
// Otherwise, if S is a tuple- like type (section 3.3.3):
// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature.
var temp1 = [true, false, true]
var [d3, d4] = [1, "string", ...temp1];
// Combining both forms of destructuring,
var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] };
var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] };
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } };
var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } };

View file

@ -0,0 +1,19 @@
// The type T associated with a destructuring variable declaration is determined as follows:
// If the declaration includes a type annotation, T is that type.
var {a1, a2}: { a1: number, a2: string } = { a1: true, a2: 1 } // Error
var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error
// The type T associated with a destructuring variable declaration is determined as follows:
// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression.
var temp = { t1: true, t2: "false" };
var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error
// The type T associated with a binding element is determined as follows:
// If the binding element is a rest element, T is an array type with
// an element type E, where E is the type of the numeric index signature of S.
var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error
// When a destructuring variable declaration, binding property, or binding element specifies
// an initializer expression, the type of the initializer expression is required to be assignable
// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element.
var {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error

View file

@ -1,3 +0,0 @@
var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] };
var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] };
var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] };