diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js new file mode 100644 index 0000000000000..bf71064264ab7 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js @@ -0,0 +1,100 @@ +//// [destructuringArrayBindingPatternAndAssignment1ES5.ts] +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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 AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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 b8 = foo().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 _f = temp, c0 = _f[0], c1 = _f[1]; +var c2 = [][0]; +var _g = [[[]], [[[[]]]]], c3 = _g[0][0][0], c4 = _g[1][0][0][0][0]; +var _h = [[1], true], c5 = _h[0][0], c6 = _h[1]; +var _j = [1, 2, 3], c7 = _j[1]; +var _k = [1, 2, 3, 4], c8 = _k[3]; +var _l = [1, 2, 3, 4], c9 = _l[3]; +var _m = [1, 2, 3, 4, "hello"], c10 = _m.slice(3); +var _o = [1, 2, "string"], c11 = _o[0], c12 = _o[1], c13 = _o.slice(2); +var _p = [1, 2, "string"], c14 = _p[0], c15 = _p[1], c16 = _p[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols new file mode 100644 index 0000000000000..d8e319f41204d --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols @@ -0,0 +1,105 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) +>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) +>undefined : Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) +>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) +>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 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) +>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) +>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) +>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) +>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) + +function foo() { +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) +>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +var [...b8] = foo(); +>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) +>foo : 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 : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c0, c1] = [...temp]; +>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) +>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c2] = []; +>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) +>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) +>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) + +var [, c7] = [1, 2, 3]; +>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) + +var [,,, c8] = [1, 2, 3, 4]; +>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) + +var [,,, c9] = [1, 2, 3, 4]; +>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) +>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) +>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) +>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) +>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types new file mode 100644 index 0000000000000..bde9c867e2b48 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -0,0 +1,177 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +>a0 : any +>a1 : any +>undefined : undefined + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : boolean +>false : boolean +>a3 : number +>1 : number +>undefined : undefined + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +>b0 : number +>b1 : number +>b2 : number +>[2, 3, 4] : [number, number, number] +>2 : number +>3 : number +>4 : number + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : number +>b4 : number +>b5 : string +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +function foo() { +>foo : () => number[] + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} + +var [b6, b7] = foo(); +>b6 : number +>b7 : number +>foo() : number[] +>foo : () => number[] + +var [...b8] = foo(); +>b8 : number[] +>foo() : number[] +>foo : () => number[] + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +>temp : number[] +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [c0, c1] = [...temp]; +>c0 : number +>c1 : number +>[...temp] : number[] +>...temp : number +>temp : number[] + +var [c2] = []; +>c2 : any +>[] : undefined[] + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : any +>c4 : any +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : string | number +>c6 : boolean +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +var [, c7] = [1, 2, 3]; +> : undefined +>c7 : number +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, c8] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c8 : number +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, c9] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c9 : number +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>c10 : (string | number)[] +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : string | number +>c12 : string | number +>c13 : (string | number)[] +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : number +>c15 : number +>c16 : string +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js new file mode 100644 index 0000000000000..d3a5c9ff5aae9 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js @@ -0,0 +1,99 @@ +//// [destructuringArrayBindingPatternAndAssignment1ES6.ts] + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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 AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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"]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols new file mode 100644 index 0000000000000..33f9b4e88be8e --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols @@ -0,0 +1,105 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) +>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) +>undefined : Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) +>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) +>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 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) +>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) +>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) +>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) +>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) + +function foo() { +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) +>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +var [...b8] = foo(); +>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) +>foo : 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 : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c0, c1] = [...temp]; +>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) +>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c2] = []; +>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) +>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) +>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) + +var [, c7] = [1, 2, 3]; +>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) + +var [,,, c8] = [1, 2, 3, 4]; +>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) + +var [,,, c9] = [1, 2, 3, 4]; +>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) +>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) +>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) +>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) +>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types new file mode 100644 index 0000000000000..2d5d82c5efe55 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -0,0 +1,177 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +>a0 : any +>a1 : any +>undefined : undefined + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : boolean +>false : boolean +>a3 : number +>1 : number +>undefined : undefined + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +>b0 : number +>b1 : number +>b2 : number +>[2, 3, 4] : [number, number, number] +>2 : number +>3 : number +>4 : number + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : number +>b4 : number +>b5 : string +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +function foo() { +>foo : () => number[] + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} + +var [b6, b7] = foo(); +>b6 : number +>b7 : number +>foo() : number[] +>foo : () => number[] + +var [...b8] = foo(); +>b8 : number[] +>foo() : number[] +>foo : () => number[] + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +>temp : number[] +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [c0, c1] = [...temp]; +>c0 : number +>c1 : number +>[...temp] : number[] +>...temp : number +>temp : number[] + +var [c2] = []; +>c2 : any +>[] : undefined[] + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : any +>c4 : any +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : string | number +>c6 : boolean +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +var [, c7] = [1, 2, 3]; +> : undefined +>c7 : number +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, c8] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c8 : number +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, c9] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c9 : number +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>c10 : (string | number)[] +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : string | number +>c12 : string | number +>c13 : (string | number)[] +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : number +>c15 : number +>c16 : string +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt new file mode 100644 index 0000000000000..a2e5cb7e17c17 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -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 { + 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. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js new file mode 100644 index 0000000000000..fdbf47fd970ba --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js @@ -0,0 +1,60 @@ +//// [destructuringArrayBindingPatternAndAssignment2.ts] +// 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 { + 2: number; +} + +function bar(): J { + 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 +} + +function foo(idx: number): F { + return { + 2: true + } +} +var [c4, c5, c6] = foo(1); // Error + +//// [destructuringArrayBindingPatternAndAssignment2.js] +// 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 _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 diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js new file mode 100644 index 0000000000000..f201b17deda0d --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js @@ -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"]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols new file mode 100644 index 0000000000000..017a7f71e612e --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols @@ -0,0 +1,101 @@ +=== 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 : Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5)) +>undefined : Symbol(undefined) + +var { a2 }: any = {}; +>a2 : 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 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5)) +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50)) + +var {1: b3} = { 1: "string" }; +>b3 : Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5)) + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5)) +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) + +var {b5: { b52 } } = { b5: { b52 } }; +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) +>b52 : 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 : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + [idx: number]: boolean; +>idx : Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5)) +} + +function foo(): F { +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { + 1: true + }; +} + +function bar(): F { +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { + 2: true + }; +} +var {1: c0} = foo(); +>c0 : Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5)) +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5)) +>bar : 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 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + [str: string]: number; +>str : Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types new file mode 100644 index 0000000000000..f44adab359fed --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -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 +>undefined : undefined + +var { a2 }: any = {}; +>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, }; +>b1 : number +>{ b1:1, } : { b1: number; } +>b1 : number +>1 : number + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : any +>b21 : string +>{ b21: "string" } : { b21: string; } +>b21 : string +>"string" : string +>{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>b2 : { b21: string; } +>{ b21: "world" } : { b21: string; } +>b21 : string +>"world" : string + +var {1: b3} = { 1: "string" }; +>b3 : string +>{ 1: "string" } : { 1: string; } +>"string" : string + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : number +>1 : number +>{ b4: 100000 } : { b4: number; } +>b4 : number +>100000 : number + +var {b5: { b52 } } = { b5: { b52 } }; +>b5 : any +>b52 : any +>{ b5: { b52 } } : { b5: { b52: any; }; } +>b5 : { b52: any; } +>{ b52 } : { b52: any; } +>b52 : any + +// 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 + + [idx: number]: boolean; +>idx : number +} + +function foo(): F { +>foo : () => F +>F : F + + return { +>{ 1: true } : { [x: number]: boolean; 1: boolean; } + + 1: true +>true : boolean + + }; +} + +function bar(): F { +>bar : () => F +>F : F + + return { +>{ 2: true } : { [x: number]: boolean; 2: boolean; } + + 2: true +>true : boolean + + }; +} +var {1: c0} = foo(); +>c0 : boolean +>foo() : F +>foo : () => F + +var {1: c1} = bar(); +>c1 : boolean +>bar() : F +>bar : () => F + +// 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 + + [str: string]: number; +>str : string +} + +function foo1(): F1 { +>foo1 : () => F1 +>F1 : F1 + + return { +>{ "prop1": 2 } : { [x: string]: number; "prop1": number; } + + "prop1": 2 +>2 : number + } +} + +var {"prop1": d1} = foo1(); +>d1 : number +>foo1() : F1 +>foo1 : () => F1 + +var {"prop2": d1} = foo1(); +>d1 : number +>foo1() : F1 +>foo1 : () => F1 + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js new file mode 100644 index 0000000000000..0173645d8a383 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js @@ -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(); diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols new file mode 100644 index 0000000000000..11289210ee4d4 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols @@ -0,0 +1,101 @@ +=== 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 : Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5)) +>undefined : Symbol(undefined) + +var { a2 }: any = {}; +>a2 : 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 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5)) +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50)) + +var {1: b3} = { 1: "string" }; +>b3 : Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5)) + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5)) +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) + +var {b5: { b52 } } = { b5: { b52 } }; +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) +>b52 : 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 : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + [idx: number]: boolean; +>idx : Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5)) +} + +function foo(): F { +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { + 1: true + }; +} + +function bar(): F { +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { + 2: true + }; +} +var {1: c0} = foo(); +>c0 : Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5)) +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5)) +>bar : 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 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + [str: string]: number; +>str : Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types new file mode 100644 index 0000000000000..47d4474b63e38 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -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 +>undefined : undefined + +var { a2 }: any = {}; +>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, }; +>b1 : number +>{ b1:1, } : { b1: number; } +>b1 : number +>1 : number + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : any +>b21 : string +>{ b21: "string" } : { b21: string; } +>b21 : string +>"string" : string +>{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>b2 : { b21: string; } +>{ b21: "world" } : { b21: string; } +>b21 : string +>"world" : string + +var {1: b3} = { 1: "string" }; +>b3 : string +>{ 1: "string" } : { 1: string; } +>"string" : string + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : number +>1 : number +>{ b4: 100000 } : { b4: number; } +>b4 : number +>100000 : number + +var {b5: { b52 } } = { b5: { b52 } }; +>b5 : any +>b52 : any +>{ b5: { b52 } } : { b5: { b52: any; }; } +>b5 : { b52: any; } +>{ b52 } : { b52: any; } +>b52 : any + +// 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 + + [idx: number]: boolean; +>idx : number +} + +function foo(): F { +>foo : () => F +>F : F + + return { +>{ 1: true } : { [x: number]: boolean; 1: boolean; } + + 1: true +>true : boolean + + }; +} + +function bar(): F { +>bar : () => F +>F : F + + return { +>{ 2: true } : { [x: number]: boolean; 2: boolean; } + + 2: true +>true : boolean + + }; +} +var {1: c0} = foo(); +>c0 : boolean +>foo() : F +>foo : () => F + +var {1: c1} = bar(); +>c1 : boolean +>bar() : F +>bar : () => F + +// 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 + + [str: string]: number; +>str : string +} + +function foo1(): F1 { +>foo1 : () => F1 +>F1 : F1 + + return { +>{ "prop1": 2 } : { [x: string]: number; "prop1": number; } + + "prop1": 2 +>2 : number + } +} + +var {"prop1": d1} = foo1(); +>d1 : number +>foo1() : F1 +>foo1 : () => F1 + +var {"prop2": d1} = foo1(); +>d1 : number +>foo1() : F1 +>foo1 : () => F1 + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt new file mode 100644 index 0000000000000..9025f24f99217 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -0,0 +1,42 @@ +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(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. + var {i}: string | number = { i: 2 }; + ~~~ +!!! error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. +!!! error TS2322: Type '{ i: number; }' is not assignable to type 'number'. + ~ +!!! error TS2459: Type 'string | number' has no property 'i' and no string index signature. + var {i1}: string | number| {} = { i1: 2 }; + ~~ +!!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. + var { f2: {f21} = { f212: "string" } }: any = undefined; + ~~~ +!!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. + var { ...d1 } = { + ~~~ +!!! error TS1180: Property destructuring pattern expected. + a: 1, b: 1, d1: 9, e: 10 + } + var {1} = { 1 }; + ~ +!!! error TS1005: ':' expected. + ~ +!!! error TS1005: ':' expected. + var {"prop"} = { "prop": 1 }; + ~ +!!! error TS1005: ':' expected. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js new file mode 100644 index 0000000000000..77288e6a5427a --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -0,0 +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 { ...d1 } = { + a: 1, b: 1, d1: 9, e: 10 +} +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 d1 = { + a: 1, b: 1, d1: 9, e: 10 +}.d1; +var = { 1: }[1]; +var = { "prop": 1 }["prop"]; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js new file mode 100644 index 0000000000000..6d731538d186c --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js @@ -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 c1 = [1, 2, 3].slice(0); +var c2 = [1, 2, 3, "string"].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 _m = [1, "string"], d1 = _m[0], d2 = _m[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 _o = [1, "string"].concat(temp1), d3 = _o[0], d4 = _o[1]; +// Combining both forms of destructuring, +var _p = { e: [1, 2, { b1: 4, b4: 0 }] }.e, e1 = _p[0], e2 = _p[1], _q = _p[2], e3 = _q === void 0 ? { b1: 1000, b4: 200 } : _q; +var _r = { f: [1, 2, { f3: 4, f5: 0 }] }.f, f1 = _r[0], f2 = _r[1], _s = _r[2], f4 = _s.f3, f5 = _s.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 _t = { g: { g1: [1, 2] } }.g.g1, g1 = _t === void 0 ? [undefined, null] : _t; +var _u = { h: { h1: [1, 2] } }.h.h1, h1 = _u === void 0 ? [undefined, null] : _u; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols new file mode 100644 index 0000000000000..2a2f2a358ca5b --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols @@ -0,0 +1,114 @@ +=== 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 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 5)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52)) + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5)) +>a4 : Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11)) +>a5 : Symbol(a5, Decl(destructuringVariableDeclaration1ES5.ts, 3, 16)) + +// 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" } }; +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50)) + +var temp = { t1: true, t2: "false" }; +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22)) + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5)) +>b3 : Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60)) + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5)) +>b6 : Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12)) +>b7 : Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(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 : Symbol(c1, Decl(destructuringVariableDeclaration1ES5.ts, 15, 5)) + +var [...c2] = [1,2,3, "string"]; +>c2 : Symbol(c2, Decl(destructuringVariableDeclaration1ES5.ts, 16, 5)) + +// 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 : Symbol(d1, Decl(destructuringVariableDeclaration1ES5.ts, 22, 5)) +>d2 : Symbol(d2, Decl(destructuringVariableDeclaration1ES5.ts, 22, 8)) + +// 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 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5)) +>d4 : Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8)) +>temp1 : 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 }] }; +>e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) +>e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) +>e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33)) +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) +>f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 60)) + +// 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] } }; +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) +>undefined : Symbol(undefined) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41)) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) +>undefined : Symbol(undefined) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41)) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67)) + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types new file mode 100644 index 0000000000000..ef3507f0f8b0b --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -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 +>a2 : string +>a1 : number +>a2 : string +>{ a1: 10, a2: "world" } : { a1: number; a2: string; } +>a1 : number +>10 : number +>a2 : string +>"world" : string + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : number +>a4 : string +>a5 : boolean +>[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 +>{ b11: "string" } : { b11: string; } +>b11 : string +>"string" : string +>{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>b1 : { b11: string; } +>{ b11: "world" } : { b11: string; } +>b11 : string +>"world" : string + +var temp = { t1: true, t2: "false" }; +>temp : { t1: boolean; t2: string; } +>{ t1: true, t2: "false" } : { t1: boolean; t2: string; } +>t1 : boolean +>true : boolean +>t2 : string +>"false" : string + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : number +>3 : number +>b3 : boolean +>true : boolean +>b4 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } +>[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 +>false : boolean +>t2 : string +>"hello" : string + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : any +>3 : number +>b6 : any +>true : boolean +>b7 : any +>temp : { t1: boolean; t2: string; } +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined +>undefined : 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]; +>c1 : number[] +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [...c2] = [1,2,3, "string"]; +>c2 : (string | number)[] +>[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 +>d2 : string +>[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[] +>[true, false, true] : boolean[] +>true : boolean +>false : boolean +>true : boolean + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : string | number | boolean +>d4 : string | number | boolean +>[1, "string", ...temp1] : (string | number | boolean)[] +>1 : number +>"string" : string +>...temp1 : boolean +>temp1 : boolean[] + +// 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 +>e2 : number +>e3 : { b1: number; b4: number; } +>{ b1: 1000, b4: 200 } : { b1: number; b4: number; } +>b1 : number +>1000 : number +>b4 : number +>200 : number +>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } +>e : [number, number, { b1: number; b4: number; }] +>[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 +>4 : number +>b4 : number +>0 : number + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : any +>f1 : number +>f2 : number +>f3 : any +>f4 : number +>f5 : number +> : undefined +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } +>f : [number, number, { f3: number; f5: number; }] +>[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 +>4 : number +>f5 : number +>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[] +>[undefined, null] : null[] +>undefined : undefined +>null : null +>g : { g1: any[]; } +>g1 : any[] +>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } +>g : { g1: number[]; } +>{ g1: [1, 2] } : { g1: number[]; } +>g1 : number[] +>[1, 2] : number[] +>1 : number +>2 : number + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : any +>h1 : number[] +>[undefined, null] : null[] +>undefined : undefined +>null : null +>h : { h1: number[]; } +>h1 : number[] +>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } +>h : { h1: number[]; } +>{ h1: [1, 2] } : { h1: number[]; } +>h1 : number[] +>[1, 2] : number[] +>1 : number +>2 : number + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.js b/tests/baselines/reference/destructuringVariableDeclaration1ES6.js new file mode 100644 index 0000000000000..53b888471a189 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.js @@ -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] } }; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols new file mode 100644 index 0000000000000..0350ff3525144 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols @@ -0,0 +1,114 @@ +=== 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 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 5)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52)) + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5)) +>a4 : Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11)) +>a5 : Symbol(a5, Decl(destructuringVariableDeclaration1ES6.ts, 3, 16)) + +// 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" } }; +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50)) + +var temp = { t1: true, t2: "false" }; +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22)) + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5)) +>b3 : Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60)) + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5)) +>b6 : Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12)) +>b7 : Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(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 : Symbol(c1, Decl(destructuringVariableDeclaration1ES6.ts, 15, 5)) + +var [...c2] = [1,2,3, "string"]; +>c2 : Symbol(c2, Decl(destructuringVariableDeclaration1ES6.ts, 16, 5)) + +// 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 : Symbol(d1, Decl(destructuringVariableDeclaration1ES6.ts, 22, 5)) +>d2 : Symbol(d2, Decl(destructuringVariableDeclaration1ES6.ts, 22, 8)) + +// 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 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5)) +>d4 : Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8)) +>temp1 : 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 }] }; +>e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) +>e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) +>e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33)) +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) +>f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 60)) + +// 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] } }; +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) +>undefined : Symbol(undefined) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41)) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) +>undefined : Symbol(undefined) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41)) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67)) + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types new file mode 100644 index 0000000000000..d62574c28f0c9 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -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 +>a2 : string +>a1 : number +>a2 : string +>{ a1: 10, a2: "world" } : { a1: number; a2: string; } +>a1 : number +>10 : number +>a2 : string +>"world" : string + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : number +>a4 : string +>a5 : boolean +>[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 +>{ b11: "string" } : { b11: string; } +>b11 : string +>"string" : string +>{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>b1 : { b11: string; } +>{ b11: "world" } : { b11: string; } +>b11 : string +>"world" : string + +var temp = { t1: true, t2: "false" }; +>temp : { t1: boolean; t2: string; } +>{ t1: true, t2: "false" } : { t1: boolean; t2: string; } +>t1 : boolean +>true : boolean +>t2 : string +>"false" : string + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : number +>3 : number +>b3 : boolean +>true : boolean +>b4 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } +>[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 +>false : boolean +>t2 : string +>"hello" : string + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : any +>3 : number +>b6 : any +>true : boolean +>b7 : any +>temp : { t1: boolean; t2: string; } +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined +>undefined : 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]; +>c1 : number[] +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [...c2] = [1,2,3, "string"]; +>c2 : (string | number)[] +>[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 +>d2 : string +>[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[] +>[true, false, true] : boolean[] +>true : boolean +>false : boolean +>true : boolean + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : string | number | boolean +>d4 : string | number | boolean +>[1, "string", ...temp1] : (string | number | boolean)[] +>1 : number +>"string" : string +>...temp1 : boolean +>temp1 : boolean[] + +// 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 +>e2 : number +>e3 : { b1: number; b4: number; } +>{ b1: 1000, b4: 200 } : { b1: number; b4: number; } +>b1 : number +>1000 : number +>b4 : number +>200 : number +>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } +>e : [number, number, { b1: number; b4: number; }] +>[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 +>4 : number +>b4 : number +>0 : number + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : any +>f1 : number +>f2 : number +>f3 : any +>f4 : number +>f5 : number +> : undefined +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } +>f : [number, number, { f3: number; f5: number; }] +>[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 +>4 : number +>f5 : number +>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[] +>[undefined, null] : null[] +>undefined : undefined +>null : null +>g : { g1: any[]; } +>g1 : any[] +>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } +>g : { g1: number[]; } +>{ g1: [1, 2] } : { g1: number[]; } +>g1 : number[] +>[1, 2] : number[] +>1 : number +>2 : number + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : any +>h1 : number[] +>[undefined, null] : null[] +>undefined : undefined +>null : null +>h : { h1: number[]; } +>h1 : number[] +>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } +>h : { h1: number[]; } +>{ h1: [1, 2] } : { h1: number[]; } +>h1 : number[] +>[1, 2] : number[] +>1 : number +>2 : number + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt new file mode 100644 index 0000000000000..1a6558377434e --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.js b/tests/baselines/reference/destructuringVariableDeclaration2.js new file mode 100644 index 0000000000000..a4fadd850d75b --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration2.js @@ -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 diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts new file mode 100644 index 0000000000000..5b594e3cada9d --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts @@ -0,0 +1,52 @@ +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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"]; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts new file mode 100644 index 0000000000000..9b631706bfdb4 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts @@ -0,0 +1,53 @@ +// @target: es6 + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision 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"]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts new file mode 100644 index 0000000000000..bc5a2da176b96 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts @@ -0,0 +1,34 @@ +// 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 { + 2: number; +} + +function bar(): J { + 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 +} + +function foo(idx: number): F { + return { + 2: true + } +} +var [c4, c5, c6] = foo(1); // Error \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts new file mode 100644 index 0000000000000..e25a11ba5b05f --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts @@ -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(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts new file mode 100644 index 0000000000000..a99b48d75da21 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts @@ -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(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts new file mode 100644 index 0000000000000..2b3192bc9a2c3 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts @@ -0,0 +1,10 @@ +// 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 { ...d1 } = { + a: 1, b: 1, d1: 9, e: 10 +} +var {1} = { 1 }; +var {"prop"} = { "prop": 1 }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts new file mode 100644 index 0000000000000..6121c00a7844e --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts @@ -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] } }; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts new file mode 100644 index 0000000000000..dee06e000ce0f --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts @@ -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] } }; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts new file mode 100644 index 0000000000000..8ffd3bddd58a6 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts @@ -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 \ No newline at end of file