diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 981e3f9fe36cb..006d6df215de3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4561,11 +4561,11 @@ namespace ts { const elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false, /*allowAsyncIterables*/ false); const index = pattern.elements.indexOf(declaration); if (declaration.dotDotDotToken) { - // If the parent is a tuple type, the rest element has an array type with a union of the + // If the parent is a tuple type, the rest element has a tuple type of the // remaining tuple element types. Otherwise, the rest element has an array type with same // element type as the parent type. type = isTupleType(parentType) ? - getArrayLiteralType((parentType.typeArguments || emptyArray).slice(index, getTypeReferenceArity(parentType))) : + sliceTupleType(parentType, index) : createArrayType(elementType); } else { @@ -8539,6 +8539,20 @@ namespace ts { return links.resolvedType; } + function sliceTupleType(type: TupleTypeReference, index: number) { + const tuple = type.target; + if (tuple.hasRestElement) { + // don't slice off rest element + index = Math.min(index, getTypeReferenceArity(type) - 1); + } + return createTupleType( + (type.typeArguments || emptyArray).slice(index), + Math.max(0, tuple.minLength - index), + tuple.hasRestElement, + tuple.associatedNames && tuple.associatedNames.slice(index), + ); + } + function getTypeFromOptionalTypeNode(node: OptionalTypeNode): Type { const type = getTypeFromTypeNode(node.type); return strictNullChecks ? getOptionalType(type) : type; @@ -21130,7 +21144,7 @@ namespace ts { else { checkGrammarForDisallowedTrailingComma(node.elements, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma); const type = isTupleType(sourceType) ? - getArrayLiteralType((sourceType.typeArguments || emptyArray).slice(elementIndex, getTypeReferenceArity(sourceType))) : + sliceTupleType(sourceType, elementIndex) : createArrayType(elementType); return checkDestructuringAssignment(restExpression, type, checkMode); } diff --git a/tests/baselines/reference/declarationEmitDestructuring3.types b/tests/baselines/reference/declarationEmitDestructuring3.types index 537de8e1e7450..c1d9c1f9a1d09 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.types +++ b/tests/baselines/reference/declarationEmitDestructuring3.types @@ -8,7 +8,7 @@ function bar([x, z, ...w]) { } function foo([x, ...y] = [1, "string", true]) { } >foo : ([x, ...y]?: [number, string, boolean]) => void >x : number ->y : (string | boolean)[] +>y : [string, boolean] >[1, "string", true] : [number, string, boolean] >1 : 1 >"string" : "string" diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js index f0438ba5a8a36..9a34c58e8de4a 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -22,10 +22,10 @@ var _f = [1, "hello", true], x19 = _f[0], y19 = _f[1], z19 = _f[2], a13 = _f.sli //// [declarationEmitDestructuringArrayPattern4.d.ts] declare var a5: number[]; -declare var x14: number, a6: number[]; -declare var x15: number, y15: number, a7: number[]; -declare var x16: number, y16: number, z16: number, a8: any[]; +declare var x14: number, a6: [number, number]; +declare var x15: number, y15: number, a7: [number]; +declare var x16: number, y16: number, z16: number, a8: []; declare var a9: (string | number | boolean)[]; -declare var x17: number, a10: (string | boolean)[]; -declare var x18: number, y18: string, a12: boolean[]; -declare var x19: number, y19: string, z19: boolean, a13: any[]; +declare var x17: number, a10: [string, boolean]; +declare var x18: number, y18: string, a12: [boolean]; +declare var x19: number, y19: string, z19: boolean, a13: []; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types index 52c292997a918..45ae44b3d3a08 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -8,7 +8,7 @@ var [...a5] = [1, 2, 3]; var [x14, ...a6] = [1, 2, 3]; >x14 : number ->a6 : number[] +>a6 : [number, number] >[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 @@ -17,7 +17,7 @@ var [x14, ...a6] = [1, 2, 3]; var [x15, y15, ...a7] = [1, 2, 3]; >x15 : number >y15 : number ->a7 : number[] +>a7 : [number] >[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 @@ -27,7 +27,7 @@ var [x16, y16, z16, ...a8] = [1, 2, 3]; >x16 : number >y16 : number >z16 : number ->a8 : any[] +>a8 : [] >[1, 2, 3] : [number, number, number] >1 : 1 >2 : 2 @@ -42,7 +42,7 @@ var [...a9] = [1, "hello", true]; var [x17, ...a10] = [1, "hello", true]; >x17 : number ->a10 : (string | boolean)[] +>a10 : [string, boolean] >[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" @@ -51,7 +51,7 @@ var [x17, ...a10] = [1, "hello", true]; var [x18, y18, ...a12] = [1, "hello", true]; >x18 : number >y18 : string ->a12 : boolean[] +>a12 : [boolean] >[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" @@ -61,7 +61,7 @@ var [x19, y19, z19, ...a13] = [1, "hello", true]; >x19 : number >y19 : string >z19 : boolean ->a13 : any[] +>a13 : [] >[1, "hello", true] : [number, string, boolean] >1 : 1 >"hello" : "hello" diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 920f995ef3202..08db9a7a3f2ac 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -223,37 +223,39 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): var x = ([a, b] = [1, 2]); } - function f20() { + function f20(v: [number, number, number]) { var x: number; var y: number; var z: number; - var a: number[]; - var a3: any[]; - var [...a] = [1, 2, 3]; - var [x, ...a] = [1, 2, 3]; - var [x, y, ...a] = [1, 2, 3]; - var [x, y, z, ...a3] = [1, 2, 3]; - [...a] = [1, 2, 3]; - [x, ...a] = [1, 2, 3]; - [x, y, ...a] = [1, 2, 3]; - [x, y, z, ...a3] = [1, 2, 3]; + var a0: []; + var a1: [number]; + var a2: [number, number]; + var a3: [number, number, number]; + var [...a3] = v; + var [x, ...a2] = v; + var [x, y, ...a1] = v; + var [x, y, z, ...a0] = v; + [...a3] = v; + [x, ...a2] = v; + [x, y, ...a1] = v; + [x, y, z, ...a0] = v; } - function f21() { + function f21(v: [number, string, boolean]) { var x: number; var y: string; var z: boolean; - var a0: (number | string | boolean)[]; - var a1: (string | boolean)[]; - var a2: boolean[]; - var a3: any[]; - var [...a0] = [1, "hello", true]; - var [x, ...a1] = [1, "hello", true]; - var [x, y, ...a2] = [1, "hello", true]; - var [x, y, z, ...a3] = [1, "hello", true]; - [...a0] = [1, "hello", true]; - [x, ...a1] = [1, "hello", true]; - [x, y, ...a2] = [1, "hello", true]; - [x, y, z, ...a3] = [1, "hello", true]; + var a0: [number, string, boolean]; + var a1: [string, boolean]; + var a2: [boolean]; + var a3: []; + var [...a0] = v; + var [x, ...a1] = v; + var [x, y, ...a2] = v; + var [x, y, z, ...a3] = v; + [...a0] = v; + [x, ...a1] = v; + [x, y, ...a2] = v; + [x, y, z, ...a3] = v; } \ No newline at end of file diff --git a/tests/baselines/reference/declarationsAndAssignments.js b/tests/baselines/reference/declarationsAndAssignments.js index b4bba2412893a..f092d0c1f928f 100644 --- a/tests/baselines/reference/declarationsAndAssignments.js +++ b/tests/baselines/reference/declarationsAndAssignments.js @@ -149,38 +149,40 @@ function f19() { var x = ([a, b] = [1, 2]); } -function f20() { +function f20(v: [number, number, number]) { var x: number; var y: number; var z: number; - var a: number[]; - var a3: any[]; - var [...a] = [1, 2, 3]; - var [x, ...a] = [1, 2, 3]; - var [x, y, ...a] = [1, 2, 3]; - var [x, y, z, ...a3] = [1, 2, 3]; - [...a] = [1, 2, 3]; - [x, ...a] = [1, 2, 3]; - [x, y, ...a] = [1, 2, 3]; - [x, y, z, ...a3] = [1, 2, 3]; + var a0: []; + var a1: [number]; + var a2: [number, number]; + var a3: [number, number, number]; + var [...a3] = v; + var [x, ...a2] = v; + var [x, y, ...a1] = v; + var [x, y, z, ...a0] = v; + [...a3] = v; + [x, ...a2] = v; + [x, y, ...a1] = v; + [x, y, z, ...a0] = v; } -function f21() { +function f21(v: [number, string, boolean]) { var x: number; var y: string; var z: boolean; - var a0: (number | string | boolean)[]; - var a1: (string | boolean)[]; - var a2: boolean[]; - var a3: any[]; - var [...a0] = [1, "hello", true]; - var [x, ...a1] = [1, "hello", true]; - var [x, y, ...a2] = [1, "hello", true]; - var [x, y, z, ...a3] = [1, "hello", true]; - [...a0] = [1, "hello", true]; - [x, ...a1] = [1, "hello", true]; - [x, y, ...a2] = [1, "hello", true]; - [x, y, z, ...a3] = [1, "hello", true]; + var a0: [number, string, boolean]; + var a1: [string, boolean]; + var a2: [boolean]; + var a3: []; + var [...a0] = v; + var [x, ...a1] = v; + var [x, y, ...a2] = v; + var [x, y, z, ...a3] = v; + [...a0] = v; + [x, ...a1] = v; + [x, y, ...a2] = v; + [x, y, z, ...a3] = v; } @@ -320,24 +322,24 @@ function f19() { _d = [[2, 3]][0], _e = _d === void 0 ? [1, 2] : _d, a = _e[0], b = _e[1]; var x = (_f = [1, 2], a = _f[0], b = _f[1], _f); } -function f20() { - var _a, _b, _c; +function f20(v) { var x; var y; var z; - var a; + var a0; + var a1; + var a2; var a3; - var a = [1, 2, 3].slice(0); - var _d = [1, 2, 3], x = _d[0], a = _d.slice(1); - var _e = [1, 2, 3], x = _e[0], y = _e[1], a = _e.slice(2); - var _f = [1, 2, 3], x = _f[0], y = _f[1], z = _f[2], a3 = _f.slice(3); - a = [1, 2, 3].slice(0); - _a = [1, 2, 3], x = _a[0], a = _a.slice(1); - _b = [1, 2, 3], x = _b[0], y = _b[1], a = _b.slice(2); - _c = [1, 2, 3], x = _c[0], y = _c[1], z = _c[2], a3 = _c.slice(3); + var a3 = v.slice(0); + var x = v[0], a2 = v.slice(1); + var x = v[0], y = v[1], a1 = v.slice(2); + var x = v[0], y = v[1], z = v[2], a0 = v.slice(3); + a3 = v.slice(0); + x = v[0], a2 = v.slice(1); + x = v[0], y = v[1], a1 = v.slice(2); + x = v[0], y = v[1], z = v[2], a0 = v.slice(3); } -function f21() { - var _a, _b, _c; +function f21(v) { var x; var y; var z; @@ -345,12 +347,12 @@ function f21() { var a1; var a2; var a3; - var a0 = [1, "hello", true].slice(0); - var _d = [1, "hello", true], x = _d[0], a1 = _d.slice(1); - var _e = [1, "hello", true], x = _e[0], y = _e[1], a2 = _e.slice(2); - var _f = [1, "hello", true], x = _f[0], y = _f[1], z = _f[2], a3 = _f.slice(3); - a0 = [1, "hello", true].slice(0); - _a = [1, "hello", true], x = _a[0], a1 = _a.slice(1); - _b = [1, "hello", true], x = _b[0], y = _b[1], a2 = _b.slice(2); - _c = [1, "hello", true], x = _c[0], y = _c[1], z = _c[2], a3 = _c.slice(3); + var a0 = v.slice(0); + var x = v[0], a1 = v.slice(1); + var x = v[0], y = v[1], a2 = v.slice(2); + var x = v[0], y = v[1], z = v[2], a3 = v.slice(3); + a0 = v.slice(0); + x = v[0], a1 = v.slice(1); + x = v[0], y = v[1], a2 = v.slice(2); + x = v[0], y = v[1], z = v[2], a3 = v.slice(3); } diff --git a/tests/baselines/reference/declarationsAndAssignments.symbols b/tests/baselines/reference/declarationsAndAssignments.symbols index 900d255345cb8..e5971d121f105 100644 --- a/tests/baselines/reference/declarationsAndAssignments.symbols +++ b/tests/baselines/reference/declarationsAndAssignments.symbols @@ -471,119 +471,143 @@ function f19() { >b : Symbol(b, Decl(declarationsAndAssignments.ts, 142, 10)) } -function f20() { +function f20(v: [number, number, number]) { >f20 : Symbol(f20, Decl(declarationsAndAssignments.ts, 148, 1)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) var x: number; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 159, 9), Decl(declarationsAndAssignments.ts, 160, 9), Decl(declarationsAndAssignments.ts, 161, 9)) var y: number; ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 160, 11), Decl(declarationsAndAssignments.ts, 161, 11)) var z: number; ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 159, 14)) - - var a: number[]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - - var a3: any[]; ->a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 159, 17)) - - var [...a] = [1, 2, 3]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - - var [x, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - - var [x, y, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - - var [x, y, z, ...a3] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 159, 14)) ->a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 159, 17)) - - [...a] = [1, 2, 3]; ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - - [x, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - - [x, y, ...a] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) ->a : Symbol(a, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 156, 9), Decl(declarationsAndAssignments.ts, 157, 11), Decl(declarationsAndAssignments.ts, 158, 14)) - - [x, y, z, ...a3] = [1, 2, 3]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 157, 9), Decl(declarationsAndAssignments.ts, 158, 9), Decl(declarationsAndAssignments.ts, 159, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 158, 11), Decl(declarationsAndAssignments.ts, 159, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 159, 14)) ->a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 159, 17)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 161, 14)) + + var a0: []; +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 161, 17)) + + var a1: [number]; +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 160, 14)) + + var a2: [number, number]; +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 156, 7), Decl(declarationsAndAssignments.ts, 159, 11)) + + var a3: [number, number, number]; +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 157, 7), Decl(declarationsAndAssignments.ts, 158, 9)) + + var [...a3] = v; +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 157, 7), Decl(declarationsAndAssignments.ts, 158, 9)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) + + var [x, ...a2] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 159, 9), Decl(declarationsAndAssignments.ts, 160, 9), Decl(declarationsAndAssignments.ts, 161, 9)) +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 156, 7), Decl(declarationsAndAssignments.ts, 159, 11)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) + + var [x, y, ...a1] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 159, 9), Decl(declarationsAndAssignments.ts, 160, 9), Decl(declarationsAndAssignments.ts, 161, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 160, 11), Decl(declarationsAndAssignments.ts, 161, 11)) +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 160, 14)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) + + var [x, y, z, ...a0] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 159, 9), Decl(declarationsAndAssignments.ts, 160, 9), Decl(declarationsAndAssignments.ts, 161, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 160, 11), Decl(declarationsAndAssignments.ts, 161, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 161, 14)) +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 161, 17)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) + + [...a3] = v; +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 157, 7), Decl(declarationsAndAssignments.ts, 158, 9)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) + + [x, ...a2] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 159, 9), Decl(declarationsAndAssignments.ts, 160, 9), Decl(declarationsAndAssignments.ts, 161, 9)) +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 156, 7), Decl(declarationsAndAssignments.ts, 159, 11)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) + + [x, y, ...a1] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 159, 9), Decl(declarationsAndAssignments.ts, 160, 9), Decl(declarationsAndAssignments.ts, 161, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 160, 11), Decl(declarationsAndAssignments.ts, 161, 11)) +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 155, 7), Decl(declarationsAndAssignments.ts, 160, 14)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) + + [x, y, z, ...a0] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 151, 7), Decl(declarationsAndAssignments.ts, 159, 9), Decl(declarationsAndAssignments.ts, 160, 9), Decl(declarationsAndAssignments.ts, 161, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 152, 7), Decl(declarationsAndAssignments.ts, 160, 11), Decl(declarationsAndAssignments.ts, 161, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 153, 7), Decl(declarationsAndAssignments.ts, 161, 14)) +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 154, 7), Decl(declarationsAndAssignments.ts, 161, 17)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 150, 13)) } -function f21() { ->f21 : Symbol(f21, Decl(declarationsAndAssignments.ts, 164, 1)) +function f21(v: [number, string, boolean]) { +>f21 : Symbol(f21, Decl(declarationsAndAssignments.ts, 166, 1)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) var x: number; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 9), Decl(declarationsAndAssignments.ts, 178, 9), Decl(declarationsAndAssignments.ts, 179, 9)) var y: string; ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 178, 11), Decl(declarationsAndAssignments.ts, 179, 11)) var z: boolean; ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 14)) - - var a0: (number | string | boolean)[]; ->a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 174, 9)) - - var a1: (string | boolean)[]; ->a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 175, 11)) - - var a2: boolean[]; ->a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 14)) - - var a3: any[]; ->a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 17)) - - var [...a0] = [1, "hello", true]; ->a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 174, 9)) - - var [x, ...a1] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) ->a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 175, 11)) - - var [x, y, ...a2] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) ->a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 14)) - - var [x, y, z, ...a3] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 14)) ->a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 17)) - - [...a0] = [1, "hello", true]; ->a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 174, 9)) - - [x, ...a1] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) ->a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 175, 11)) - - [x, y, ...a2] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) ->a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 14)) - - [x, y, z, ...a3] = [1, "hello", true]; ->x : Symbol(x, Decl(declarationsAndAssignments.ts, 167, 7), Decl(declarationsAndAssignments.ts, 175, 9), Decl(declarationsAndAssignments.ts, 176, 9), Decl(declarationsAndAssignments.ts, 177, 9)) ->y : Symbol(y, Decl(declarationsAndAssignments.ts, 168, 7), Decl(declarationsAndAssignments.ts, 176, 11), Decl(declarationsAndAssignments.ts, 177, 11)) ->z : Symbol(z, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 14)) ->a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 17)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 179, 14)) + + var a0: [number, string, boolean]; +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 9)) + + var a1: [string, boolean]; +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 11)) + + var a2: [boolean]; +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 174, 7), Decl(declarationsAndAssignments.ts, 178, 14)) + + var a3: []; +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 175, 7), Decl(declarationsAndAssignments.ts, 179, 17)) + + var [...a0] = v; +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 9)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) + + var [x, ...a1] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 9), Decl(declarationsAndAssignments.ts, 178, 9), Decl(declarationsAndAssignments.ts, 179, 9)) +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 11)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) + + var [x, y, ...a2] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 9), Decl(declarationsAndAssignments.ts, 178, 9), Decl(declarationsAndAssignments.ts, 179, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 178, 11), Decl(declarationsAndAssignments.ts, 179, 11)) +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 174, 7), Decl(declarationsAndAssignments.ts, 178, 14)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) + + var [x, y, z, ...a3] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 9), Decl(declarationsAndAssignments.ts, 178, 9), Decl(declarationsAndAssignments.ts, 179, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 178, 11), Decl(declarationsAndAssignments.ts, 179, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 179, 14)) +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 175, 7), Decl(declarationsAndAssignments.ts, 179, 17)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) + + [...a0] = v; +>a0 : Symbol(a0, Decl(declarationsAndAssignments.ts, 172, 7), Decl(declarationsAndAssignments.ts, 176, 9)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) + + [x, ...a1] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 9), Decl(declarationsAndAssignments.ts, 178, 9), Decl(declarationsAndAssignments.ts, 179, 9)) +>a1 : Symbol(a1, Decl(declarationsAndAssignments.ts, 173, 7), Decl(declarationsAndAssignments.ts, 177, 11)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) + + [x, y, ...a2] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 9), Decl(declarationsAndAssignments.ts, 178, 9), Decl(declarationsAndAssignments.ts, 179, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 178, 11), Decl(declarationsAndAssignments.ts, 179, 11)) +>a2 : Symbol(a2, Decl(declarationsAndAssignments.ts, 174, 7), Decl(declarationsAndAssignments.ts, 178, 14)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) + + [x, y, z, ...a3] = v; +>x : Symbol(x, Decl(declarationsAndAssignments.ts, 169, 7), Decl(declarationsAndAssignments.ts, 177, 9), Decl(declarationsAndAssignments.ts, 178, 9), Decl(declarationsAndAssignments.ts, 179, 9)) +>y : Symbol(y, Decl(declarationsAndAssignments.ts, 170, 7), Decl(declarationsAndAssignments.ts, 178, 11), Decl(declarationsAndAssignments.ts, 179, 11)) +>z : Symbol(z, Decl(declarationsAndAssignments.ts, 171, 7), Decl(declarationsAndAssignments.ts, 179, 14)) +>a3 : Symbol(a3, Decl(declarationsAndAssignments.ts, 175, 7), Decl(declarationsAndAssignments.ts, 179, 17)) +>v : Symbol(v, Decl(declarationsAndAssignments.ts, 168, 13)) } diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index 602ffbd76eb0d..e7db6f84fdb77 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -678,8 +678,9 @@ function f19() { >2 : 2 } -function f20() { ->f20 : () => void +function f20(v: [number, number, number]) { +>f20 : (v: [number, number, number]) => void +>v : [number, number, number] var x: number; >x : number @@ -690,95 +691,78 @@ function f20() { var z: number; >z : number - var a: number[]; ->a : number[] + var a0: []; +>a0 : [] - var a3: any[]; ->a3 : any[] + var a1: [number]; +>a1 : [number] - var [...a] = [1, 2, 3]; ->a : number[] ->[1, 2, 3] : number[] ->1 : 1 ->2 : 2 ->3 : 3 + var a2: [number, number]; +>a2 : [number, number] + + var a3: [number, number, number]; +>a3 : [number, number, number] - var [x, ...a] = [1, 2, 3]; + var [...a3] = v; +>a3 : [number, number, number] +>v : [number, number, number] + + var [x, ...a2] = v; >x : number ->a : number[] ->[1, 2, 3] : [number, number, number] ->1 : 1 ->2 : 2 ->3 : 3 +>a2 : [number, number] +>v : [number, number, number] - var [x, y, ...a] = [1, 2, 3]; + var [x, y, ...a1] = v; >x : number >y : number ->a : number[] ->[1, 2, 3] : [number, number, number] ->1 : 1 ->2 : 2 ->3 : 3 +>a1 : [number] +>v : [number, number, number] - var [x, y, z, ...a3] = [1, 2, 3]; + var [x, y, z, ...a0] = v; >x : number >y : number >z : number ->a3 : any[] ->[1, 2, 3] : [number, number, number] ->1 : 1 ->2 : 2 ->3 : 3 +>a0 : [] +>v : [number, number, number] - [...a] = [1, 2, 3]; ->[...a] = [1, 2, 3] : number[] ->[...a] : number[] ->...a : number ->a : number[] ->[1, 2, 3] : number[] ->1 : 1 ->2 : 2 ->3 : 3 + [...a3] = v; +>[...a3] = v : [number, number, number] +>[...a3] : number[] +>...a3 : number +>a3 : [number, number, number] +>v : [number, number, number] - [x, ...a] = [1, 2, 3]; ->[x, ...a] = [1, 2, 3] : [number, number, number] ->[x, ...a] : [number, ...number[]] + [x, ...a2] = v; +>[x, ...a2] = v : [number, number, number] +>[x, ...a2] : [number, ...number[]] >x : number ->...a : number ->a : number[] ->[1, 2, 3] : [number, number, number] ->1 : 1 ->2 : 2 ->3 : 3 +>...a2 : number +>a2 : [number, number] +>v : [number, number, number] - [x, y, ...a] = [1, 2, 3]; ->[x, y, ...a] = [1, 2, 3] : [number, number, number] ->[x, y, ...a] : [number, number, ...number[]] + [x, y, ...a1] = v; +>[x, y, ...a1] = v : [number, number, number] +>[x, y, ...a1] : [number, number, ...number[]] >x : number >y : number ->...a : number ->a : number[] ->[1, 2, 3] : [number, number, number] ->1 : 1 ->2 : 2 ->3 : 3 +>...a1 : number +>a1 : [number] +>v : [number, number, number] - [x, y, z, ...a3] = [1, 2, 3]; ->[x, y, z, ...a3] = [1, 2, 3] : [number, number, number] ->[x, y, z, ...a3] : [number, number, number, ...any[]] + [x, y, z, ...a0] = v; +>[x, y, z, ...a0] = v : [number, number, number] +>[x, y, z, ...a0] : [number, number, number, ...never[]] >x : number >y : number >z : number ->...a3 : any ->a3 : any[] ->[1, 2, 3] : [number, number, number] ->1 : 1 ->2 : 2 ->3 : 3 +>...a0 : never +>a0 : [] +>v : [number, number, number] } -function f21() { ->f21 : () => void +function f21(v: [number, string, boolean]) { +>f21 : (v: [number, string, boolean]) => void +>v : [number, string, boolean] var x: number; >x : number @@ -789,96 +773,72 @@ function f21() { var z: boolean; >z : boolean - var a0: (number | string | boolean)[]; ->a0 : (string | number | boolean)[] + var a0: [number, string, boolean]; +>a0 : [number, string, boolean] - var a1: (string | boolean)[]; ->a1 : (string | boolean)[] + var a1: [string, boolean]; +>a1 : [string, boolean] - var a2: boolean[]; ->a2 : boolean[] + var a2: [boolean]; +>a2 : [boolean] - var a3: any[]; ->a3 : any[] + var a3: []; +>a3 : [] - var [...a0] = [1, "hello", true]; ->a0 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] ->1 : 1 ->"hello" : "hello" ->true : true + var [...a0] = v; +>a0 : [number, string, boolean] +>v : [number, string, boolean] - var [x, ...a1] = [1, "hello", true]; + var [x, ...a1] = v; >x : number ->a1 : (string | boolean)[] ->[1, "hello", true] : [number, string, boolean] ->1 : 1 ->"hello" : "hello" ->true : true +>a1 : [string, boolean] +>v : [number, string, boolean] - var [x, y, ...a2] = [1, "hello", true]; + var [x, y, ...a2] = v; >x : number >y : string ->a2 : boolean[] ->[1, "hello", true] : [number, string, boolean] ->1 : 1 ->"hello" : "hello" ->true : true +>a2 : [boolean] +>v : [number, string, boolean] - var [x, y, z, ...a3] = [1, "hello", true]; + var [x, y, z, ...a3] = v; >x : number >y : string >z : boolean ->a3 : any[] ->[1, "hello", true] : [number, string, boolean] ->1 : 1 ->"hello" : "hello" ->true : true +>a3 : [] +>v : [number, string, boolean] - [...a0] = [1, "hello", true]; ->[...a0] = [1, "hello", true] : (string | number | true)[] + [...a0] = v; +>[...a0] = v : [number, string, boolean] >[...a0] : (string | number | boolean)[] >...a0 : string | number | boolean ->a0 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | true)[] ->1 : 1 ->"hello" : "hello" ->true : true +>a0 : [number, string, boolean] +>v : [number, string, boolean] - [x, ...a1] = [1, "hello", true]; ->[x, ...a1] = [1, "hello", true] : [number, string, true] + [x, ...a1] = v; +>[x, ...a1] = v : [number, string, boolean] >[x, ...a1] : [number, ...(string | boolean)[]] >x : number >...a1 : string | boolean ->a1 : (string | boolean)[] ->[1, "hello", true] : [number, string, true] ->1 : 1 ->"hello" : "hello" ->true : true +>a1 : [string, boolean] +>v : [number, string, boolean] - [x, y, ...a2] = [1, "hello", true]; ->[x, y, ...a2] = [1, "hello", true] : [number, string, true] + [x, y, ...a2] = v; +>[x, y, ...a2] = v : [number, string, boolean] >[x, y, ...a2] : [number, string, ...boolean[]] >x : number >y : string >...a2 : boolean ->a2 : boolean[] ->[1, "hello", true] : [number, string, true] ->1 : 1 ->"hello" : "hello" ->true : true +>a2 : [boolean] +>v : [number, string, boolean] - [x, y, z, ...a3] = [1, "hello", true]; ->[x, y, z, ...a3] = [1, "hello", true] : [number, string, true] ->[x, y, z, ...a3] : [number, string, boolean, ...any[]] + [x, y, z, ...a3] = v; +>[x, y, z, ...a3] = v : [number, string, boolean] +>[x, y, z, ...a3] : [number, string, boolean, ...never[]] >x : number >y : string >z : boolean ->...a3 : any ->a3 : any[] ->[1, "hello", true] : [number, string, true] ->1 : 1 ->"hello" : "hello" ->true : true +>...a3 : never +>a3 : [] +>v : [number, string, boolean] } diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 2d212b1e13e7f..03990bc084651 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -148,7 +148,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[] +>c10 : [number, string] >[1, 2, 3, 4, "hello"] : [number, number, number, number, string] >1 : 1 >2 : 2 @@ -159,7 +159,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; var [c11, c12, ...c13] = [1, 2, "string"]; >c11 : number >c12 : number ->c13 : string[] +>c13 : [string] >[1, 2, "string"] : [number, number, string] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types index 8ef92a8875549..cb2e801823270 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5iterable.types @@ -148,7 +148,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[] +>c10 : [number, string] >[1, 2, 3, 4, "hello"] : [number, number, number, number, string] >1 : 1 >2 : 2 @@ -159,7 +159,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; var [c11, c12, ...c13] = [1, 2, "string"]; >c11 : number >c12 : number ->c13 : string[] +>c13 : [string] >[1, 2, "string"] : [number, number, string] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index 7767cadee5a78..9a00291f79c64 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -148,7 +148,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[] +>c10 : [number, string] >[1, 2, 3, 4, "hello"] : [number, number, number, number, string] >1 : 1 >2 : 2 @@ -159,7 +159,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; var [c11, c12, ...c13] = [1, 2, "string"]; >c11 : number >c12 : number ->c13 : string[] +>c13 : [string] >[1, 2, "string"] : [number, number, string] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/destructuringTuple.js b/tests/baselines/reference/destructuringTuple.js new file mode 100644 index 0000000000000..a8a0bc6f5e3d1 --- /dev/null +++ b/tests/baselines/reference/destructuringTuple.js @@ -0,0 +1,14 @@ +//// [destructuringTuple.ts] +declare var tuple: [boolean, number, ...string[]]; + +const [a, b, c, ...rest] = tuple; + +declare var receiver: typeof tuple; + +[...receiver] = tuple; + + +//// [destructuringTuple.js] +"use strict"; +var a = tuple[0], b = tuple[1], c = tuple[2], rest = tuple.slice(3); +receiver = tuple.slice(0); diff --git a/tests/baselines/reference/destructuringTuple.symbols b/tests/baselines/reference/destructuringTuple.symbols new file mode 100644 index 0000000000000..73480505c3b14 --- /dev/null +++ b/tests/baselines/reference/destructuringTuple.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/destructuringTuple.ts === +declare var tuple: [boolean, number, ...string[]]; +>tuple : Symbol(tuple, Decl(destructuringTuple.ts, 0, 11)) + +const [a, b, c, ...rest] = tuple; +>a : Symbol(a, Decl(destructuringTuple.ts, 2, 7)) +>b : Symbol(b, Decl(destructuringTuple.ts, 2, 9)) +>c : Symbol(c, Decl(destructuringTuple.ts, 2, 12)) +>rest : Symbol(rest, Decl(destructuringTuple.ts, 2, 15)) +>tuple : Symbol(tuple, Decl(destructuringTuple.ts, 0, 11)) + +declare var receiver: typeof tuple; +>receiver : Symbol(receiver, Decl(destructuringTuple.ts, 4, 11)) +>tuple : Symbol(tuple, Decl(destructuringTuple.ts, 0, 11)) + +[...receiver] = tuple; +>receiver : Symbol(receiver, Decl(destructuringTuple.ts, 4, 11)) +>tuple : Symbol(tuple, Decl(destructuringTuple.ts, 0, 11)) + diff --git a/tests/baselines/reference/destructuringTuple.types b/tests/baselines/reference/destructuringTuple.types new file mode 100644 index 0000000000000..fe3bf84746fc2 --- /dev/null +++ b/tests/baselines/reference/destructuringTuple.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/destructuringTuple.ts === +declare var tuple: [boolean, number, ...string[]]; +>tuple : [boolean, number, ...string[]] + +const [a, b, c, ...rest] = tuple; +>a : boolean +>b : number +>c : string +>rest : string[] +>tuple : [boolean, number, ...string[]] + +declare var receiver: typeof tuple; +>receiver : [boolean, number, ...string[]] +>tuple : [boolean, number, ...string[]] + +[...receiver] = tuple; +>[...receiver] = tuple : [boolean, number, ...string[]] +>[...receiver] : (string | number | boolean)[] +>...receiver : string | number | boolean +>receiver : [boolean, number, ...string[]] +>tuple : [boolean, number, ...string[]] + diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.types b/tests/baselines/reference/destructuringVariableDeclaration2.types index 43b83a4d74f86..ddb560f4e24c0 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration2.types +++ b/tests/baselines/reference/destructuringVariableDeclaration2.types @@ -59,7 +59,7 @@ var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error >c4 : number >c5 : number > : undefined ->c6 : any[] +>c6 : [] >[1, 2, { c3: 4, c5: 0 }] : [number, number, { c3: number; c5: number; }, undefined?] >1 : 1 >2 : 2 diff --git a/tests/baselines/reference/restElementMustBeLast.types b/tests/baselines/reference/restElementMustBeLast.types index 12e5ec84abefe..68276c7ef3d29 100644 --- a/tests/baselines/reference/restElementMustBeLast.types +++ b/tests/baselines/reference/restElementMustBeLast.types @@ -1,6 +1,6 @@ === tests/cases/conformance/types/rest/restElementMustBeLast.ts === var [...a, x] = [1, 2, 3]; // Error, rest must be last element ->a : number[] +>a : [number, number, number] >x : number >[1, 2, 3] : [number, number, number] >1 : 1 @@ -11,7 +11,7 @@ var [...a, x] = [1, 2, 3]; // Error, rest must be last element >[...a, x] = [1, 2, 3] : number[] >[...a, x] : number[] >...a : number ->a : number[] +>a : [number, number, number] >x : number >[1, 2, 3] : number[] >1 : 1 diff --git a/tests/baselines/reference/restElementWithAssignmentPattern3.errors.txt b/tests/baselines/reference/restElementWithAssignmentPattern3.errors.txt deleted file mode 100644 index 6906bdde36f5c..0000000000000 --- a/tests/baselines/reference/restElementWithAssignmentPattern3.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts(3,6): error TS2322: Type 'string | number' is not assignable to type 'string'. - Type 'number' is not assignable to type 'string'. -tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts(3,9): error TS2322: Type 'string | number' is not assignable to type 'number'. - Type 'string' is not assignable to type 'number'. - - -==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern3.ts (2 errors) ==== - var a: string, b: number; - var tuple: [string, number] = ["", 1]; - [...[a, b = 0]] = tuple; - ~ -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. -!!! error TS2322: Type 'number' is not assignable to type 'string'. - ~ -!!! error TS2322: Type 'string | number' 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/restElementWithAssignmentPattern4.errors.txt b/tests/baselines/reference/restElementWithAssignmentPattern4.errors.txt index 258d091523930..f455d3fc04a09 100644 --- a/tests/baselines/reference/restElementWithAssignmentPattern4.errors.txt +++ b/tests/baselines/reference/restElementWithAssignmentPattern4.errors.txt @@ -1,14 +1,9 @@ -tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,10): error TS2322: Type 'string | number' is not assignable to type 'string'. - Type 'number' is not assignable to type 'string'. -tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,18): error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature. +tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts(3,18): error TS2459: Type '[string, number]' has no property 'b' and no string index signature. -==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts (2 errors) ==== +==== tests/cases/conformance/es6/destructuring/restElementWithAssignmentPattern4.ts (1 errors) ==== var a: string, b: number; var tuple: [string, number] = ["", 1]; [...{ 0: a = "", b }] = tuple; - ~ -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. -!!! error TS2322: Type 'number' is not assignable to type 'string'. ~ -!!! error TS2459: Type '(string | number)[]' has no property 'b' and no string index signature. \ No newline at end of file +!!! error TS2459: Type '[string, number]' has no property 'b' and no string index signature. \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types index 556a32c05568e..8ea11e087f861 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types @@ -426,7 +426,7 @@ for (let [nameMA, [primarySkillA, secondarySkillA]] = ["trimmer", ["trimming", " for (let [numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] >robotA : [number, string, string] >i : number >0 : 0 @@ -445,7 +445,7 @@ for (let [numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { } for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i : number @@ -465,7 +465,7 @@ for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { } for (let [numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] >[2, "trimmer", "trimming"] : [number, string, string] >2 : 2 >"trimmer" : "trimmer" @@ -486,7 +486,7 @@ for (let [numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i >numberA3 : number } for (let [...multiRobotAInfo] = multiRobotA, i = 0; i < 1; i++) { ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] >multiRobotA : [string, [string, string]] >i : number >0 : 0 @@ -501,10 +501,10 @@ for (let [...multiRobotAInfo] = multiRobotA, i = 0; i < 1; i++) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] } for (let [...multiRobotAInfo] = getMultiRobot(), i = 0; i < 1; i++) { ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] >getMultiRobot() : [string, [string, string]] >getMultiRobot : () => [string, [string, string]] >i : number @@ -520,7 +520,7 @@ for (let [...multiRobotAInfo] = getMultiRobot(), i = 0; i < 1; i++) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] } for (let [...multiRobotAInfo] = ["trimmer", ["trimming", "edging"]], i = 0; i < 1; i++) { >multiRobotAInfo : (string | string[])[] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types index 1887e43f38fda..ee16f28a9d589 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types @@ -531,7 +531,7 @@ for (let [numberA3 = -1, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >robotA : [number, string, string] >i : number >0 : 0 @@ -552,7 +552,7 @@ for (let [numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i : number @@ -574,7 +574,7 @@ for (let [numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >[2, "trimmer", "trimming"] : [number, string, string] >2 : 2 >"trimmer" : "trimmer" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types index 9925a0812a2ab..57fa951a2c797 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types @@ -310,7 +310,7 @@ for (let [nameMA, [primarySkillA, secondarySkillA]] of [multiRobotA, multiRobotB for (let [numberA3, ...robotAInfo] of robots) { >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] >robots : [number, string, string][] console.log(numberA3); @@ -322,7 +322,7 @@ for (let [numberA3, ...robotAInfo] of robots) { } for (let [numberA3, ...robotAInfo] of getRobots()) { >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -335,7 +335,7 @@ for (let [numberA3, ...robotAInfo] of getRobots()) { } for (let [numberA3, ...robotAInfo] of [robotA, robotB]) { >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] @@ -348,7 +348,7 @@ for (let [numberA3, ...robotAInfo] of [robotA, robotB]) { >numberA3 : number } for (let [...multiRobotAInfo] of multiRobots) { ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] >multiRobots : [string, [string, string]][] console.log(multiRobotAInfo); @@ -356,10 +356,10 @@ for (let [...multiRobotAInfo] of multiRobots) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] } for (let [...multiRobotAInfo] of getMultiRobots()) { ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] >getMultiRobots() : [string, [string, string]][] >getMultiRobots : () => [string, [string, string]][] @@ -368,10 +368,10 @@ for (let [...multiRobotAInfo] of getMultiRobots()) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] } for (let [...multiRobotAInfo] of [multiRobotA, multiRobotB]) { ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] >[multiRobotA, multiRobotB] : [string, [string, string]][] >multiRobotA : [string, [string, string]] >multiRobotB : [string, [string, string]] @@ -381,5 +381,5 @@ for (let [...multiRobotAInfo] of [multiRobotA, multiRobotB]) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] } diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types index ceb9eabc15046..34689acf92089 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types @@ -405,7 +405,7 @@ for (let [numberA3 = -1, ...robotAInfo] of robots) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >robots : [number, string, string][] console.log(numberA3); @@ -419,7 +419,7 @@ for (let [numberA3 = -1, ...robotAInfo] of getRobots()) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -434,7 +434,7 @@ for (let [numberA3 = -1, ...robotAInfo] of [robotA, robotB]) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types index 91067aca14bc7..2758457edbe7a 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types @@ -58,14 +58,14 @@ function foo3([numberA2, nameA2, skillA2]: Robot) { function foo4([numberA3, ...robotAInfo]: Robot) { >foo4 : ([numberA3, ...robotAInfo]: [number, string, string]) => void >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] console.log(robotAInfo); >console.log(robotAInfo) : void >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->robotAInfo : string[] +>robotAInfo : [string, string] } foo1(robotA); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern2.types b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern2.types index e2f678a8b335e..1cdced45404f3 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern2.types @@ -58,14 +58,14 @@ function foo3([nameMA, [primarySkillA, secondarySkillA]]: Robot) { function foo4([...multiRobotAInfo]: Robot) { >foo4 : ([...multiRobotAInfo]: [string, [string, string]]) => void ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] console.log(multiRobotAInfo); >console.log(multiRobotAInfo) : void >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] } foo1(robotA); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types index 75ef0fefd1fc1..60345aa2b73c4 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types @@ -82,7 +82,7 @@ function foo4([numberA3 = -1, ...robotAInfo]: Robot = [-1, "name", "skill"]) { >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >[-1, "name", "skill"] : [number, string, string] >-1 : -1 >1 : 1 @@ -94,7 +94,7 @@ function foo4([numberA3 = -1, ...robotAInfo]: Robot = [-1, "name", "skill"]) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->robotAInfo : string[] +>robotAInfo : [string, string] } foo1(robotA); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types index 2af7c28876ae8..2ed0777aa80b2 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types @@ -57,7 +57,7 @@ let [numberC, nameC, skillC] = [3, "edging", "Trimming edges"]; let [numberA3, ...robotAInfo] = robotA; >numberA3 : number ->robotAInfo : string[] +>robotAInfo : [string, string] >robotA : [number, string, string] if (nameA == nameA2) { diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern2.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern2.types index 79ad97e7f42b6..94b0ff295a200 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern2.types @@ -59,7 +59,7 @@ let [nameMC2, [primarySkillC, secondarySkillC]] = ["roomba", ["vaccum", "mopping >"mopping" : "mopping" let [...multiRobotAInfo] = multiRobotA; ->multiRobotAInfo : (string | [string, string])[] +>multiRobotAInfo : [string, [string, string]] >multiRobotA : [string, [string, string]] if (nameMB == nameMA) { diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types index 5d258faf5b338..7e4ae19d39494 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types @@ -71,7 +71,7 @@ let [numberA3 = -1, ...robotAInfo] = robotA; >numberA3 : number >-1 : -1 >1 : 1 ->robotAInfo : string[] +>robotAInfo : [string, string] >robotA : [number, string, string] if (nameA == nameA2) { diff --git a/tests/cases/compiler/destructuringTuple.ts b/tests/cases/compiler/destructuringTuple.ts new file mode 100644 index 0000000000000..c6a8431da0b3a --- /dev/null +++ b/tests/cases/compiler/destructuringTuple.ts @@ -0,0 +1,9 @@ +// @strict: true + +declare var tuple: [boolean, number, ...string[]]; + +const [a, b, c, ...rest] = tuple; + +declare var receiver: typeof tuple; + +[...receiver] = tuple; diff --git a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts index e45df9c45dfd1..7ab33f99a1e84 100644 --- a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts +++ b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts @@ -148,36 +148,38 @@ function f19() { var x = ([a, b] = [1, 2]); } -function f20() { +function f20(v: [number, number, number]) { var x: number; var y: number; var z: number; - var a: number[]; - var a3: any[]; - var [...a] = [1, 2, 3]; - var [x, ...a] = [1, 2, 3]; - var [x, y, ...a] = [1, 2, 3]; - var [x, y, z, ...a3] = [1, 2, 3]; - [...a] = [1, 2, 3]; - [x, ...a] = [1, 2, 3]; - [x, y, ...a] = [1, 2, 3]; - [x, y, z, ...a3] = [1, 2, 3]; -} - -function f21() { + var a0: []; + var a1: [number]; + var a2: [number, number]; + var a3: [number, number, number]; + var [...a3] = v; + var [x, ...a2] = v; + var [x, y, ...a1] = v; + var [x, y, z, ...a0] = v; + [...a3] = v; + [x, ...a2] = v; + [x, y, ...a1] = v; + [x, y, z, ...a0] = v; +} + +function f21(v: [number, string, boolean]) { var x: number; var y: string; var z: boolean; - var a0: (number | string | boolean)[]; - var a1: (string | boolean)[]; - var a2: boolean[]; - var a3: any[]; - var [...a0] = [1, "hello", true]; - var [x, ...a1] = [1, "hello", true]; - var [x, y, ...a2] = [1, "hello", true]; - var [x, y, z, ...a3] = [1, "hello", true]; - [...a0] = [1, "hello", true]; - [x, ...a1] = [1, "hello", true]; - [x, y, ...a2] = [1, "hello", true]; - [x, y, z, ...a3] = [1, "hello", true]; + var a0: [number, string, boolean]; + var a1: [string, boolean]; + var a2: [boolean]; + var a3: []; + var [...a0] = v; + var [x, ...a1] = v; + var [x, y, ...a2] = v; + var [x, y, z, ...a3] = v; + [...a0] = v; + [x, ...a1] = v; + [x, y, ...a2] = v; + [x, y, z, ...a3] = v; }