diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts
index 0271ac73105..6e956889b49 100644
--- a/src/compiler/diagnosticInformationMap.generated.ts
+++ b/src/compiler/diagnosticInformationMap.generated.ts
@@ -1,6 +1,5 @@
//
///
-/* @internal */
module ts {
export var Diagnostics = {
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },
diff --git a/tests/baselines/reference/destructuringParameterDeclaration.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration.errors.txt
deleted file mode 100644
index 643305a0167..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration.errors.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'.
- Property 'z' is missing in type '{}'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,14): error TS2300: Duplicate identifier 'z'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,18): error TS2300: Duplicate identifier 'z'.
-
-
-==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts (4 errors) ====
- enum Foo { a }
- function a({x, a}: { x: number, a: number }) { }
- function a1({z: {x, y: {j}}}) { }
- function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
- function a3({z} = {z:10}) { }
- function a4({z=10}) { }
- function a6({b}: { b: number|string|boolean } = { b: "hello" }) { }
- a2();
- a2({ z: { x: "hello" , y: { j: Foo.a } }});
- a3();
- a3({ z: Foo.a });
- a4({});
- a6({ b: 10 });
- a6({ b: true });
-
- // error
- a4();
- ~~~~
-!!! error TS2346: Supplied parameters do not match any signature of call target.
- a3({});
- ~~
-!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'.
-!!! error TS2345: Property 'z' is missing in type '{}'.
- function a5([z], z: number) { }
- ~
-!!! error TS2300: Duplicate identifier 'z'.
- ~
-!!! error TS2300: Duplicate identifier 'z'.
-
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringParameterDeclaration.js b/tests/baselines/reference/destructuringParameterDeclaration.js
deleted file mode 100644
index da979430ff3..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration.js
+++ /dev/null
@@ -1,58 +0,0 @@
-//// [destructuringParameterDeclaration.ts]
-enum Foo { a }
-function a({x, a}: { x: number, a: number }) { }
-function a1({z: {x, y: {j}}}) { }
-function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
-function a3({z} = {z:10}) { }
-function a4({z=10}) { }
-function a6({b}: { b: number|string|boolean } = { b: "hello" }) { }
-a2();
-a2({ z: { x: "hello" , y: { j: Foo.a } }});
-a3();
-a3({ z: Foo.a });
-a4({});
-a6({ b: 10 });
-a6({ b: true });
-
-// error
-a4();
-a3({});
-function a5([z], z: number) { }
-
-
-//// [destructuringParameterDeclaration.js]
-var Foo;
-(function (Foo) {
- Foo[Foo["a"] = 0] = "a";
-})(Foo || (Foo = {}));
-function a(_a) {
- var x = _a.x, a = _a.a;
-}
-function a1(_a) {
- var _b = _a.z, x = _b.x, j = _b.y.j;
-}
-function a2(_a) {
- var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j;
-}
-function a3(_a) {
- var z = (_a === void 0 ? { z: 10 } : _a).z;
-}
-function a4(_a) {
- var _b = _a.z, z = _b === void 0 ? 10 : _b;
-}
-function a6(_a) {
- var b = (_a === void 0 ? { b: "hello" } : _a).b;
-}
-a2();
-a2({ z: { x: "hello", y: { j: Foo.a } } });
-a3();
-a3({ z: Foo.a });
-a4({});
-a6({ b: 10 });
-a6({ b: true });
-// error
-a4();
-a3({});
-function a5(_a, z) {
- var z = _a[0];
-}
diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt
index 2651be05038..cc0e8167d1c 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt
+++ b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt
@@ -1,48 +1,233 @@
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(5,16): error TS1048: A rest parameter cannot have an initializer.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(11,13): error TS2370: A rest parameter must be of an array type.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(12,18): error TS1047: A rest parameter cannot be optional.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,17): error TS1048: A rest parameter cannot have an initializer.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
- Type 'boolean' is not assignable to type 'number'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'.
- Type 'boolean' is not assignable to type 'string | number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(7,10): error TS2393: Duplicate function implementation.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(10,10): error TS2393: Duplicate function implementation.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,4): error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'.
+ Property 'x' is missing in type '(string | number | string[][])[]'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,29): error TS1005: ',' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(15,4): error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(28,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(28,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(35,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'.
+ Types of property 'x' are incompatible.
+ Type 'string' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(44,14): error TS2300: Duplicate identifier 'z'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(44,18): error TS2300: Duplicate identifier 'z'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(50,4): error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'.
+ Types of property 'z' are incompatible.
+ Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(52,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'.
+ Property 'z' is missing in type '{}'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(53,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'.
+ Types of property 'z' are incompatible.
Type 'boolean' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(59,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'.
+ Types of property 'z' are incompatible.
+ Type 'boolean' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(62,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'.
+ Types of property 'b' are incompatible.
+ Type 'boolean' is not assignable to type 'string | number'.
+ Type 'boolean' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(66,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
+ Types of property '2' are incompatible.
+ Type 'boolean' is not assignable to type '[[any]]'.
+ Property '0' is missing in type 'Boolean'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(68,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'.
+ Types of property '2' are incompatible.
+ Type '[[string]]' is not assignable to type '[[number]]'.
+ Types of property '0' are incompatible.
+ Type '[string]' is not assignable to type '[number]'.
+ Types of property '0' are incompatible.
+ Type 'string' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(73,10): error TS2393: Duplicate function implementation.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(74,10): error TS2393: Duplicate function implementation.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(75,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(76,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(97,7): error TS2420: Class 'C4' incorrectly implements interface 'F2'.
+ Types of property 'd4' are incompatible.
+ Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'.
+ Types of parameters '__0' and '__0' are incompatible.
+ Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'.
+ Property 'z' is missing in type '{ x: any; y: any; c: any; }'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(98,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
-==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (6 errors) ====
- type arrayString = Array
- type someArray = Array | number[];
- type stringOrNumArray = Array;
+==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (23 errors) ====
+ // A parameter declaration may specify either an identifier or a binding pattern.
+ // The identifiers specified in parameter declarations and binding patterns
+ // in a parameter list must be unique within that parameter list.
- function a3(...x = [1,2,3]) { }
- ~
-!!! error TS1048: A rest parameter cannot have an initializer.
- function a4(...x: (number|string)[]) { }
- function a5(...a) { }
- function a6(...a: Array) { }
- function a7(...a: arrayString) { }
- function a8(...a: stringOrNumArray) { }
- function a9(...a: someArray) { }
- ~~~~~~~~~~~~~~~
-!!! error TS2370: A rest parameter must be of an array type.
- function a10(...b?) { }
+ // If the declaration includes a type annotation, the parameter is of that type
+ function a0(x: number, y: string, z: boolean) { }
+ function a1([a, b, [[c]]]: [number, number, string[][]]) { }
+ ~~
+!!! error TS2393: Duplicate function implementation.
+ function a2(o: { x: number, a: number }) { }
+ function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { };
+ function a1({x, a}: { x: number, a: number }) { }
+ ~~
+!!! error TS2393: Duplicate function implementation.
+
+ a1([1, 2, [["world"]]]);
+ a1([1, 2, [["world"]], 3]);
+ a1([1, "string", [["world"]]); // Error
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'.
+!!! error TS2345: Property 'x' is missing in type '(string | number | string[][])[]'.
+ ~
+!!! error TS1005: ',' expected.
+ a1([1, 2, [["world"]], "string"]); // Error
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'.
+
+
+ // If the declaration includes an initializer expression (which is permitted only
+ // when the parameter list occurs in conjunction with a function body),
+ // the parameter type is the widened form (section 3.11) of the type of the initializer expression.
+
+ function b1(z = 10, y = 60, u = () => true) { }
+ function b2(z = [undefined, null]) { };
+ function b3(z = null, o = { x: 0, y: undefined }) { }
+ function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
+
+ interface F1 {
+ b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body
+ ~~~~~~
+!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
+ b6(z, y, [, a, b], {p, m: { q, r}});
+ }
+
+ b2([1, 2, 3]); // z is widen to the type any[]
+ b3("string", { x: 200, y: "string" });
+ b3("string", { x: 200, y: true });
+ b3("string", { x: "string", y: true }); // Error
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'.
+!!! error TS2345: Types of property 'x' are incompatible.
+!!! error TS2345: Type 'string' is not assignable to type 'number'.
+
+
+ // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
+ enum Foo { a }
+ function c0({z: {x, y: {j}}}) { }
+ function c1({z} = { z: 10 }) { }
+ function c2({z = 10}) { }
+ function c3({b}: { b: number|string} = { b: "hello" }) { }
+ function c4([z], z: number) { } // Duplicate identifier
+ ~
+!!! error TS2300: Duplicate identifier 'z'.
~
-!!! error TS1047: A rest parameter cannot be optional.
- function a11(...b = [1,2,3]) { }
- ~
-!!! error TS1048: A rest parameter cannot have an initializer.
+!!! error TS2300: Duplicate identifier 'z'.
+ function c5([a, b, [[c]]]) { }
+ function c6([a, b, [[c=1]]]) { }
+ c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} }
+ c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} }
+ c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} }
+ ~~~~~~~
+!!! error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'.
+!!! error TS2345: Types of property 'z' are incompatible.
+!!! error TS2345: Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'.
- a4(1, 2, "hello", true);
- ~~~~
-!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
-!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
- var array = [1, 2, 3];
- var array2 = [true, false, "hello"];
- a5([...array]);
- a4(...array);
- a4(...array2);
+ c1({}); // Error, implied type is {z:number}?
+ ~~
+!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'.
+!!! error TS2345: Property 'z' is missing in type '{}'.
+ c1({ z: true }); // Error, implied type is {z:number}?
+ ~~~~~~~~~~~
+!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'.
+!!! error TS2345: Types of property 'z' are incompatible.
+!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
+ c1(); // Implied type is {z:number}?
+ c1({ z: 1 }) // Implied type is {z:number}?
+
+ c2({}); // Implied type is {z?: number}
+ c2({z:1}); // Implied type is {z?: number}
+ c2({z:false}); // Error, implied type is {z?: number}
~~~~~~~~~
-!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'.
-!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'.
-!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
\ No newline at end of file
+!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'.
+!!! error TS2345: Types of property 'z' are incompatible.
+!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
+
+ c3({ b: 1 }); // Implied type is { b: number|string }.
+ c3({ b: true }); // Error, implied type is { b: number|string }.
+ ~~~~~~~~~~~
+!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'.
+!!! error TS2345: Types of property 'b' are incompatible.
+!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'.
+!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
+
+ c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
+ c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
+ c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
+ ~~~~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
+!!! error TS2345: Types of property '2' are incompatible.
+!!! error TS2345: Type 'boolean' is not assignable to type '[[any]]'.
+!!! error TS2345: Property '0' is missing in type 'Boolean'.
+
+ c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
+ ~~~~~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'.
+!!! error TS2345: Types of property '2' are incompatible.
+!!! error TS2345: Type '[[string]]' is not assignable to type '[[number]]'.
+!!! error TS2345: Types of property '0' are incompatible.
+!!! error TS2345: Type '[string]' is not assignable to type '[number]'.
+!!! error TS2345: Types of property '0' are incompatible.
+!!! error TS2345: Type 'string' is not assignable to type 'number'.
+
+ // A parameter can be marked optional by following its name or binding pattern with a question mark (?)
+ // or by including an initializer.
+
+ function d0(x?) { }
+ ~~
+!!! error TS2393: Duplicate function implementation.
+ function d0(x = 10) { }
+ ~~
+!!! error TS2393: Duplicate function implementation.
+ function d1([a, b, c]?) { }
+ ~~~~~~~~~~
+!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
+ function d2({x, y, z}?) { }
+ ~~~~~~~~~~
+!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
+
+ interface F2 {
+ d3([a, b, c]?);
+ d4({x, y, z}?);
+ e0([a, b, c]);
+ }
+
+ class C2 implements F2 {
+ constructor() { }
+ d3() { }
+ d4() { }
+ e0([a, b, c]) { }
+ }
+
+ class C3 implements F2 {
+ d3([a, b, c]) { }
+ d4({x, y, z}) { }
+ e0([a, b, c]) { }
+ }
+
+ class C4 implements F2 {
+ ~~
+!!! error TS2420: Class 'C4' incorrectly implements interface 'F2'.
+!!! error TS2420: Types of property 'd4' are incompatible.
+!!! error TS2420: Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'.
+!!! error TS2420: Types of parameters '__0' and '__0' are incompatible.
+!!! error TS2420: Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'.
+!!! error TS2420: Property 'z' is missing in type '{ x: any; y: any; c: any; }'.
+ d3([a, b, c]?) { }
+ ~~~~~~~~~~
+!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
+ d4({x, y, c}) { }
+ e0([a, b, q]) { }
+ }
+
+ function d5({x, y} = { x: 1, y: 2 }) { }
+ d5(); // Parameter is optional as its declaration included an initializer
+
+
+
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.js b/tests/baselines/reference/destructuringParameterDeclaration1.js
index 37967ddb441..d8963511838 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration1.js
+++ b/tests/baselines/reference/destructuringParameterDeclaration1.js
@@ -1,86 +1,249 @@
//// [destructuringParameterDeclaration1.ts]
-type arrayString = Array
-type someArray = Array | number[];
-type stringOrNumArray = Array;
+// A parameter declaration may specify either an identifier or a binding pattern.
+// The identifiers specified in parameter declarations and binding patterns
+// in a parameter list must be unique within that parameter list.
-function a3(...x = [1,2,3]) { }
-function a4(...x: (number|string)[]) { }
-function a5(...a) { }
-function a6(...a: Array) { }
-function a7(...a: arrayString) { }
-function a8(...a: stringOrNumArray) { }
-function a9(...a: someArray) { }
-function a10(...b?) { }
-function a11(...b = [1,2,3]) { }
+// If the declaration includes a type annotation, the parameter is of that type
+function a0(x: number, y: string, z: boolean) { }
+function a1([a, b, [[c]]]: [number, number, string[][]]) { }
+function a2(o: { x: number, a: number }) { }
+function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { };
+function a1({x, a}: { x: number, a: number }) { }
+
+a1([1, 2, [["world"]]]);
+a1([1, 2, [["world"]], 3]);
+a1([1, "string", [["world"]]); // Error
+a1([1, 2, [["world"]], "string"]); // Error
-a4(1, 2, "hello", true);
-var array = [1, 2, 3];
-var array2 = [true, false, "hello"];
-a5([...array]);
-a4(...array);
-a4(...array2);
+// If the declaration includes an initializer expression (which is permitted only
+// when the parameter list occurs in conjunction with a function body),
+// the parameter type is the widened form (section 3.11) of the type of the initializer expression.
+
+function b1(z = 10, y = 60, u = () => true) { }
+function b2(z = [undefined, null]) { };
+function b3(z = null, o = { x: 0, y: undefined }) { }
+function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
+
+interface F1 {
+ b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body
+ b6(z, y, [, a, b], {p, m: { q, r}});
+}
+
+b2([1, 2, 3]); // z is widen to the type any[]
+b3("string", { x: 200, y: "string" });
+b3("string", { x: 200, y: true });
+b3("string", { x: "string", y: true }); // Error
+
+
+// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
+enum Foo { a }
+function c0({z: {x, y: {j}}}) { }
+function c1({z} = { z: 10 }) { }
+function c2({z = 10}) { }
+function c3({b}: { b: number|string} = { b: "hello" }) { }
+function c4([z], z: number) { } // Duplicate identifier
+function c5([a, b, [[c]]]) { }
+function c6([a, b, [[c=1]]]) { }
+
+c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} }
+c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} }
+c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} }
+
+c1({}); // Error, implied type is {z:number}?
+c1({ z: true }); // Error, implied type is {z:number}?
+c1(); // Implied type is {z:number}?
+c1({ z: 1 }) // Implied type is {z:number}?
+
+c2({}); // Implied type is {z?: number}
+c2({z:1}); // Implied type is {z?: number}
+c2({z:false}); // Error, implied type is {z?: number}
+
+c3({ b: 1 }); // Implied type is { b: number|string }.
+c3({ b: true }); // Error, implied type is { b: number|string }.
+
+c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
+c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
+c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
+
+c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
+
+// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
+// or by including an initializer.
+
+function d0(x?) { }
+function d0(x = 10) { }
+function d1([a, b, c]?) { }
+function d2({x, y, z}?) { }
+
+interface F2 {
+ d3([a, b, c]?);
+ d4({x, y, z}?);
+ e0([a, b, c]);
+}
+
+class C2 implements F2 {
+ constructor() { }
+ d3() { }
+ d4() { }
+ e0([a, b, c]) { }
+}
+
+class C3 implements F2 {
+ d3([a, b, c]) { }
+ d4({x, y, z}) { }
+ e0([a, b, c]) { }
+}
+
+class C4 implements F2 {
+ d3([a, b, c]?) { }
+ d4({x, y, c}) { }
+ e0([a, b, q]) { }
+}
+
+function d5({x, y} = { x: 1, y: 2 }) { }
+d5(); // Parameter is optional as its declaration included an initializer
+
+
+
//// [destructuringParameterDeclaration1.js]
-function a3() {
- if (x === void 0) { x = [1, 2, 3]; }
- var x = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- x[_i - 0] = arguments[_i];
- }
+// A parameter declaration may specify either an identifier or a binding pattern.
+// The identifiers specified in parameter declarations and binding patterns
+// in a parameter list must be unique within that parameter list.
+// If the declaration includes a type annotation, the parameter is of that type
+function a0(x, y, z) { }
+function a1(_a) {
+ var a = _a[0], b = _a[1], c = _a[2][0][0];
}
-function a4() {
- var x = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- x[_i - 0] = arguments[_i];
- }
+function a2(o) { }
+function a3(_a) {
+ var j = _a.j, k = _a.k, _b = _a.l, m = _b.m, n = _b.n, _c = _a.q, a = _c[0], b = _c[1], c = _c[2];
}
-function a5() {
- var a = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- a[_i - 0] = arguments[_i];
- }
+;
+function a1(_a) {
+ var x = _a.x, a = _a.a;
}
-function a6() {
- var a = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- a[_i - 0] = arguments[_i];
- }
+a1([1, 2, [["world"]]]);
+a1([1, 2, [["world"]], 3]);
+a1([1, "string", [["world"]]]); // Error
+a1([1, 2, [["world"]], "string"]); // Error
+// If the declaration includes an initializer expression (which is permitted only
+// when the parameter list occurs in conjunction with a function body),
+// the parameter type is the widened form (section 3.11) of the type of the initializer expression.
+function b1(z, y, u) {
+ if (z === void 0) { z = 10; }
+ if (y === void 0) { y = 60; }
+ if (u === void 0) { u = function () { return true; }; }
}
-function a7() {
- var a = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- a[_i - 0] = arguments[_i];
- }
+function b2(z) {
+ if (z === void 0) { z = [undefined, null]; }
}
-function a8() {
- var a = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- a[_i - 0] = arguments[_i];
- }
+;
+function b3(z, o) {
+ if (z === void 0) { z = null; }
+ if (o === void 0) { o = { x: 0, y: undefined }; }
}
-function a9() {
- var a = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- a[_i - 0] = arguments[_i];
- }
+function b4(_a) {
+ var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j;
}
-function a10() {
- var b = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- b[_i - 0] = arguments[_i];
- }
+b2([1, 2, 3]); // z is widen to the type any[]
+b3("string", { x: 200, y: "string" });
+b3("string", { x: 200, y: true });
+b3("string", { x: "string", y: true }); // Error
+// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
+var Foo;
+(function (Foo) {
+ Foo[Foo["a"] = 0] = "a";
+})(Foo || (Foo = {}));
+function c0(_a) {
+ var _b = _a.z, x = _b.x, j = _b.y.j;
}
-function a11() {
- if (b === void 0) { b = [1, 2, 3]; }
- var b = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- b[_i - 0] = arguments[_i];
- }
+function c1(_a) {
+ var z = (_a === void 0 ? { z: 10 } : _a).z;
}
-a4(1, 2, "hello", true);
-var array = [1, 2, 3];
-var array2 = [true, false, "hello"];
-a5(array);
-a4.apply(void 0, array);
-a4.apply(void 0, array2);
+function c2(_a) {
+ var _b = _a.z, z = _b === void 0 ? 10 : _b;
+}
+function c3(_a) {
+ var b = (_a === void 0 ? { b: "hello" } : _a).b;
+}
+function c4(_a, z) {
+ var z = _a[0];
+} // Duplicate identifier
+function c5(_a) {
+ var a = _a[0], b = _a[1], c = _a[2][0][0];
+}
+function c6(_a) {
+ var a = _a[0], b = _a[1], _b = _a[2][0][0], c = _b === void 0 ? 1 : _b;
+}
+c0({ z: { x: 1, y: { j: "world" } } }); // Implied type is { z: {x: any, y: {j: any}} }
+c0({ z: { x: "string", y: { j: true } } }); // Implied type is { z: {x: any, y: {j: any}} }
+c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} }
+c1({}); // Error, implied type is {z:number}?
+c1({ z: true }); // Error, implied type is {z:number}?
+c1(); // Implied type is {z:number}?
+c1({ z: 1 }); // Implied type is {z:number}?
+c2({}); // Implied type is {z?: number}
+c2({ z: 1 }); // Implied type is {z?: number}
+c2({ z: false }); // Error, implied type is {z?: number}
+c3({ b: 1 }); // Implied type is { b: number|string }.
+c3({ b: true }); // Error, implied type is { b: number|string }.
+c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
+c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
+c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
+c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
+// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
+// or by including an initializer.
+function d0(x) { }
+function d0(x) {
+ if (x === void 0) { x = 10; }
+}
+function d1(_a) {
+ var a = _a[0], b = _a[1], c = _a[2];
+}
+function d2(_a) {
+ var x = _a.x, y = _a.y, z = _a.z;
+}
+var C2 = (function () {
+ function C2() {
+ }
+ C2.prototype.d3 = function () { };
+ C2.prototype.d4 = function () { };
+ C2.prototype.e0 = function (_a) {
+ var a = _a[0], b = _a[1], c = _a[2];
+ };
+ return C2;
+})();
+var C3 = (function () {
+ function C3() {
+ }
+ C3.prototype.d3 = function (_a) {
+ var a = _a[0], b = _a[1], c = _a[2];
+ };
+ C3.prototype.d4 = function (_a) {
+ var x = _a.x, y = _a.y, z = _a.z;
+ };
+ C3.prototype.e0 = function (_a) {
+ var a = _a[0], b = _a[1], c = _a[2];
+ };
+ return C3;
+})();
+var C4 = (function () {
+ function C4() {
+ }
+ C4.prototype.d3 = function (_a) {
+ var a = _a[0], b = _a[1], c = _a[2];
+ };
+ C4.prototype.d4 = function (_a) {
+ var x = _a.x, y = _a.y, c = _a.c;
+ };
+ C4.prototype.e0 = function (_a) {
+ var a = _a[0], b = _a[1], q = _a[2];
+ };
+ return C4;
+})();
+function d5(_a) {
+ var _b = _a === void 0 ? { x: 1, y: 2 } : _a, x = _b.x, y = _b.y;
+}
+d5(); // Parameter is optional as its declaration included an initializer
diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt
deleted file mode 100644
index 786571c88a5..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(5,16): error TS1048: A rest parameter cannot have an initializer.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(11,13): error TS2370: A rest parameter must be of an array type.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(12,18): error TS1047: A rest parameter cannot be optional.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(13,17): error TS1048: A rest parameter cannot have an initializer.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
- Type 'boolean' is not assignable to type 'number'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'.
- Type 'boolean' is not assignable to type 'string | number'.
- Type 'boolean' is not assignable to type 'number'.
-
-
-==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts (6 errors) ====
- type arrayString = Array
- type someArray = Array | number[];
- type stringOrNumArray = Array;
-
- function a3(...x = [1,2,3]) { }
- ~
-!!! error TS1048: A rest parameter cannot have an initializer.
- function a4(...x: (number|string)[]) { }
- function a5(...a) { }
- function a6(...a: Array) { }
- function a7(...a: arrayString) { }
- function a8(...a: stringOrNumArray) { }
- function a9(...a: someArray) { }
- ~~~~~~~~~~~~~~~
-!!! error TS2370: A rest parameter must be of an array type.
- function a10(...b?) { }
- ~
-!!! error TS1047: A rest parameter cannot be optional.
- function a11(...b = [1,2,3]) { }
- ~
-!!! error TS1048: A rest parameter cannot have an initializer.
-
-
- a4(1, 2, "hello", true);
- ~~~~
-!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
-!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
- var array = [1, 2, 3];
- var array2 = [true, false, "hello"];
- a5([...array]);
- a4(...array);
- a4(...array2);
- ~~~~~~~~~
-!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'.
-!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'.
-!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js
deleted file mode 100644
index 779f5495f56..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js
+++ /dev/null
@@ -1,39 +0,0 @@
-//// [destructuringParameterDeclaration1ES6.ts]
-type arrayString = Array
-type someArray = Array | number[];
-type stringOrNumArray = Array;
-
-function a3(...x = [1,2,3]) { }
-function a4(...x: (number|string)[]) { }
-function a5(...a) { }
-function a6(...a: Array) { }
-function a7(...a: arrayString) { }
-function a8(...a: stringOrNumArray) { }
-function a9(...a: someArray) { }
-function a10(...b?) { }
-function a11(...b = [1,2,3]) { }
-
-
-a4(1, 2, "hello", true);
-var array = [1, 2, 3];
-var array2 = [true, false, "hello"];
-a5([...array]);
-a4(...array);
-a4(...array2);
-
-//// [destructuringParameterDeclaration1ES6.js]
-function a3(...x = [1, 2, 3]) { }
-function a4(...x) { }
-function a5(...a) { }
-function a6(...a) { }
-function a7(...a) { }
-function a8(...a) { }
-function a9(...a) { }
-function a10(...b) { }
-function a11(...b = [1, 2, 3]) { }
-a4(1, 2, "hello", true);
-var array = [1, 2, 3];
-var array2 = [true, false, "hello"];
-a5([...array]);
-a4(...array);
-a4(...array2);
diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt
index afe984cc031..314c1aafee6 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt
+++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt
@@ -1,56 +1,117 @@
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,14): error TS1181: Array element destructuring pattern expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,19): error TS1005: '(' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,21): error TS1109: Expression expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,24): error TS1005: '(' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,26): error TS2304: Cannot find name 'public'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,32): error TS1005: ';' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,33): error TS1128: Declaration or statement expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,16): error TS1003: Identifier expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,21): error TS1005: '(' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(9,13): error TS2370: A rest parameter must be of an array type.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(12,24): error TS1005: ',' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(11,13): error TS2370: A rest parameter must be of an array type.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(17,13): error TS2370: A rest parameter must be of an array type.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(25,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
+ Type 'boolean' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(30,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'.
+ Type 'boolean' is not assignable to type 'string | number'.
+ Type 'boolean' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(33,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
+ Types of property '2' are incompatible.
+ Type 'string' is not assignable to type '[[any]]'.
+ Property '0' is missing in type 'String'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(34,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'.
+ Property '2' is missing in type '[number, number]'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(41,5): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
+ Type 'string | number' is not assignable to type 'number'.
+ Type 'string' is not assignable to type 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(45,24): error TS1005: ',' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(50,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
+ Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(59,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
+ Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'.
-==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (11 errors) ====
- "use strict"
- function a({while}) { }
- function a1({public}) { }
- function a2({public: x}) { }
- function a3({while: y}) { }
- function a4([while, for, public]){ }
- ~~~~~
-!!! error TS1181: Array element destructuring pattern expected.
- ~
-!!! error TS1005: '(' expected.
- ~~~
-!!! error TS1109: Expression expected.
- ~
-!!! error TS1005: '(' expected.
- ~~~~~~
-!!! error TS2304: Cannot find name 'public'.
- ~
-!!! error TS1005: ';' expected.
- ~
-!!! error TS1128: Declaration or statement expected.
- function a5(...while) { }
- ~~~~~
-!!! error TS1003: Identifier expected.
- ~
-!!! error TS1005: '(' expected.
- function a6(...public) { }
- function a7(...a: string) { }
- ~~~~~~~~~~~~
+==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (10 errors) ====
+ // If the parameter is a rest parameter, the parameter type is any[]
+ // A type annotation for a rest parameter must denote an array type.
+
+ // RestParameter:
+ // ... Identifier TypeAnnotation(opt)
+
+ type arrayString = Array
+ type someArray = Array | number[];
+ type stringOrNumArray = Array;
+
+ function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2370: A rest parameter must be of an array type.
+ function a1(...x: (number|string)[]) { }
+ function a2(...a) { }
+ function a3(...a: Array) { }
+ function a4(...a: arrayString) { }
+ function a5(...a: stringOrNumArray) { }
+ function a6(...a: someArray) { } // Error, rest parameter must be array type
+ ~~~~~~~~~~~~~~~
+!!! error TS2370: A rest parameter must be of an array type.
+ function a7(...b?) { } // Error, can't be optional
+ function a8(...b = [1,2,3]) { } // Error, can't have initializer
+ function a9([a, b, [[c]]]) { }
+ function a10([a, b, [[c]], ...x]) { }
+ function a11([a, b, c, ...x]: number[]) { }
+
+
+ a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
+ ~~~~
+!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
+!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
+ var array = [1, 2, 3];
+ var array2 = [true, false, "hello"];
+ a2([...array]);
+ a1(...array);
+ a1(...array2); // Error parameter type is (number|string)[]
+ ~~~~~~~~~
+!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'.
+!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'.
+!!! error TS2345: Type 'boolean' is not assignable to type 'number'.
+
+ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
+ a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
+!!! error TS2345: Types of property '2' are incompatible.
+!!! error TS2345: Type 'string' is not assignable to type '[[any]]'.
+!!! error TS2345: Property '0' is missing in type 'String'.
+ a9([1, 2]); // Error, parameter type is [any, any, [[any]]]
+ ~~~~~~
+!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'.
+!!! error TS2345: Property '2' is missing in type '[number, number]'.
+
+ a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
+ a10([1, 2, 3, false, true]); // Parameter type is any[]
+ a10([1, 2]); // Parameter type is any[]
+
+ a11([1, 2]); // Parameter type is number[]
+ a11([1, 2, "string"]); // Error, parameter type is number[]
+ ~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
+!!! error TS2345: Type 'string | number' is not assignable to type 'number'.
+!!! error TS2345: Type 'string' is not assignable to type 'number'.
+
class C {
- constructor(public ...a) { }
+ constructor(public ...a) { } // Rest parameter can't have accessibilityModifier
~~~
!!! error TS1005: ',' expected.
}
+ // Rest parameter with generic
+ function foo(...a: T[]) { }
+ foo("hello", 1, 2); // Error
+ ~~~
+!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
+!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
+ foo("hello", 1, 2);
+ foo("hello", "world");
+
+ enum E { a, b }
+ const enum E1 { a, b }
+ function foo1(...a: T[]) { }
+ foo1(1, 2, 3, E.a);
+ foo1(1, 2, 3, E1.a, E.b);
+ foo1(1, 2, "string", E1.a, E.b); // Error
+ ~~~~
+!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
+!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'.
- a2({ public: 1 });
- a3({ while: 1 });
- a({ while: 1 });
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js
index ba6d7548442..11bda7049e2 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration2.js
+++ b/tests/baselines/reference/destructuringParameterDeclaration2.js
@@ -1,65 +1,178 @@
//// [destructuringParameterDeclaration2.ts]
-"use strict"
-function a({while}) { }
-function a1({public}) { }
-function a2({public: x}) { }
-function a3({while: y}) { }
-function a4([while, for, public]){ }
-function a5(...while) { }
-function a6(...public) { }
-function a7(...a: string) { }
+// If the parameter is a rest parameter, the parameter type is any[]
+// A type annotation for a rest parameter must denote an array type.
+
+// RestParameter:
+// ... Identifier TypeAnnotation(opt)
+
+type arrayString = Array
+type someArray = Array | number[];
+type stringOrNumArray = Array;
+
+function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type
+function a1(...x: (number|string)[]) { }
+function a2(...a) { }
+function a3(...a: Array) { }
+function a4(...a: arrayString) { }
+function a5(...a: stringOrNumArray) { }
+function a6(...a: someArray) { } // Error, rest parameter must be array type
+function a7(...b?) { } // Error, can't be optional
+function a8(...b = [1,2,3]) { } // Error, can't have initializer
+function a9([a, b, [[c]]]) { }
+function a10([a, b, [[c]], ...x]) { }
+function a11([a, b, c, ...x]: number[]) { }
+
+
+a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
+var array = [1, 2, 3];
+var array2 = [true, false, "hello"];
+a2([...array]);
+a1(...array);
+a1(...array2); // Error parameter type is (number|string)[]
+
+a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
+a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
+a9([1, 2]); // Error, parameter type is [any, any, [[any]]]
+
+a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
+a10([1, 2, 3, false, true]); // Parameter type is any[]
+a10([1, 2]); // Parameter type is any[]
+
+a11([1, 2]); // Parameter type is number[]
+a11([1, 2, "string"]); // Error, parameter type is number[]
+
class C {
- constructor(public ...a) { }
+ constructor(public ...a) { } // Rest parameter can't have accessibilityModifier
}
+// Rest parameter with generic
+function foo(...a: T[]) { }
+foo("hello", 1, 2); // Error
+foo("hello", 1, 2);
+foo("hello", "world");
+
+enum E { a, b }
+const enum E1 { a, b }
+function foo1(...a: T[]) { }
+foo1(1, 2, 3, E.a);
+foo1(1, 2, 3, E1.a, E.b);
+foo1(1, 2, "string", E1.a, E.b); // Error
-a2({ public: 1 });
-a3({ while: 1 });
-a({ while: 1 });
//// [destructuringParameterDeclaration2.js]
-"use strict";
-function a(_a) {
- var while = _a.while;
-}
-function a1(_a) {
- var public = _a.public;
-}
-function a2(_a) {
- var x = _a.public;
-}
-function a3(_a) {
- var y = _a.while;
-}
-while (, )
- for (, public; ; )
- ;
-{ }
-while () { }
-function a6() {
- var public = [];
+// If the parameter is a rest parameter, the parameter type is any[]
+// A type annotation for a rest parameter must denote an array type.
+function a0() {
+ var x = [];
for (var _i = 0; _i < arguments.length; _i++) {
- public[_i - 0] = arguments[_i];
+ x[_i - 0] = arguments[_i];
+ }
+} // Error, rest parameter must be array type
+function a1() {
+ var x = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ x[_i - 0] = arguments[_i];
}
}
-function a7() {
+function a2() {
var a = [];
for (var _i = 0; _i < arguments.length; _i++) {
a[_i - 0] = arguments[_i];
}
}
+function a3() {
+ var a = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ a[_i - 0] = arguments[_i];
+ }
+}
+function a4() {
+ var a = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ a[_i - 0] = arguments[_i];
+ }
+}
+function a5() {
+ var a = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ a[_i - 0] = arguments[_i];
+ }
+}
+function a6() {
+ var a = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ a[_i - 0] = arguments[_i];
+ }
+} // Error, rest parameter must be array type
+function a7() {
+ var b = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ b[_i - 0] = arguments[_i];
+ }
+} // Error, can't be optional
+function a8() {
+ if (b === void 0) { b = [1, 2, 3]; }
+ var b = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ b[_i - 0] = arguments[_i];
+ }
+} // Error, can't have initializer
+function a9(_a) {
+ var a = _a[0], b = _a[1], c = _a[2][0][0];
+}
+function a10(_a) {
+ var a = _a[0], b = _a[1], c = _a[2][0][0], x = _a.slice(3);
+}
+function a11(_a) {
+ var a = _a[0], b = _a[1], c = _a[2], x = _a.slice(3);
+}
+a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
+var array = [1, 2, 3];
+var array2 = [true, false, "hello"];
+a2(array);
+a1.apply(void 0, array);
+a1.apply(void 0, array2); // Error parameter type is (number|string)[]
+a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
+a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
+a9([1, 2]); // Error, parameter type is [any, any, [[any]]]
+a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
+a10([1, 2, 3, false, true]); // Parameter type is any[]
+a10([1, 2]); // Parameter type is any[]
+a11([1, 2]); // Parameter type is number[]
+a11([1, 2, "string"]); // Error, parameter type is number[]
var C = (function () {
function C(public) {
var a = [];
for (var _i = 1; _i < arguments.length; _i++) {
a[_i - 1] = arguments[_i];
}
- }
+ } // Rest parameter can't have accessibilityModifier
return C;
})();
-a2({ public: 1 });
-a3({ while: 1 });
-a({ while: 1 });
+// Rest parameter with generic
+function foo() {
+ var a = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ a[_i - 0] = arguments[_i];
+ }
+}
+foo("hello", 1, 2); // Error
+foo("hello", 1, 2);
+foo("hello", "world");
+var E;
+(function (E) {
+ E[E["a"] = 0] = "a";
+ E[E["b"] = 1] = "b";
+})(E || (E = {}));
+function foo1() {
+ var a = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ a[_i - 0] = arguments[_i];
+ }
+}
+foo1(1, 2, 3, E.a);
+foo1(1, 2, 3, 0 /* a */, E.b);
+foo1(1, 2, "string", 0 /* a */, E.b); // Error
diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js
deleted file mode 100644
index 6e86aa2c001..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js
+++ /dev/null
@@ -1,42 +0,0 @@
-//// [destructuringParameterDeclaration2ES6.ts]
-"use strict"
-function a({while}) { }
-function a1({public}) { }
-function a2({public: x}) { }
-function a3({while: y}) { }
-function a4([while, for, public]){ }
-function a5(...while) { }
-function a6(...public) { }
-function a7(...a: string) { }
-
-class C {
- constructor(public ...a) { }
-}
-
-
-a2({ public: 1 });
-a3({ while: 1 });
-a({ while: 1 });
-
-
-
-//// [destructuringParameterDeclaration2ES6.js]
-"use strict";
-function a({ while }) { }
-function a1({ public }) { }
-function a2({ public: x }) { }
-function a3({ while: y }) { }
-while (, )
- for (, public; ; )
- ;
-{ }
-while () { }
-function a6(...public) { }
-function a7(...a) { }
-class C {
- constructor(public, ...a) {
- }
-}
-a2({ public: 1 });
-a3({ while: 1 });
-a({ while: 1 });
diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3.errors.txt
similarity index 60%
rename from tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt
rename to tests/baselines/reference/destructuringParameterDeclaration3.errors.txt
index 762a0e1dd8a..57777582731 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt
+++ b/tests/baselines/reference/destructuringParameterDeclaration3.errors.txt
@@ -1,22 +1,24 @@
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,14): error TS1181: Array element destructuring pattern expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,19): error TS1005: '(' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,21): error TS1109: Expression expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,24): error TS1005: '(' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,26): error TS2304: Cannot find name 'public'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,32): error TS1005: ';' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,33): error TS1128: Declaration or statement expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,16): error TS1003: Identifier expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,21): error TS1005: '(' expected.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(9,13): error TS2370: A rest parameter must be of an array type.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(12,24): error TS1005: ',' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,14): error TS1181: Array element destructuring pattern expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,19): error TS1005: '(' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,21): error TS1109: Expression expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,24): error TS1005: '(' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,26): error TS2304: Cannot find name 'public'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,32): error TS1005: ';' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,33): error TS1128: Declaration or statement expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(10,16): error TS1003: Identifier expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(10,21): error TS1005: '(' expected.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(12,13): error TS2370: A rest parameter must be of an array type.
-==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts (11 errors) ====
+==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts (10 errors) ====
+ // A parameter declaration may specify either an identifier or a binding pattern.
+
+ // Reserved words are not allowed to be used as an identifier in parameter declaration
"use strict"
+
+ // Error
function a({while}) { }
function a1({public}) { }
- function a2({public: x}) { }
- function a3({while: y}) { }
function a4([while, for, public]){ }
~~~~~
!!! error TS1181: Array element destructuring pattern expected.
@@ -41,16 +43,12 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.
function a7(...a: string) { }
~~~~~~~~~~~~
!!! error TS2370: A rest parameter must be of an array type.
-
- class C {
- constructor(public ...a) { }
- ~~~
-!!! error TS1005: ',' expected.
- }
-
-
- a2({ public: 1 });
- a3({ while: 1 });
a({ while: 1 });
+ // No Error
+ function b1({public: x}) { }
+ function b2({while: y}) { }
+ b1({ public: 1 });
+ b2({ while: 1 });
+
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.js b/tests/baselines/reference/destructuringParameterDeclaration3.js
index 82d1404881c..a1abb86bd63 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration3.js
+++ b/tests/baselines/reference/destructuringParameterDeclaration3.js
@@ -1,51 +1,61 @@
//// [destructuringParameterDeclaration3.ts]
-function a([x, [y, z], [[j]]]) {
- return [x, y, z, j];
-}
+// A parameter declaration may specify either an identifier or a binding pattern.
-function a1([...x]) {
- return [x];
-}
+// Reserved words are not allowed to be used as an identifier in parameter declaration
+"use strict"
-function a2({public} = { "public": "1" }) {
- return public;
-}
+// Error
+function a({while}) { }
+function a1({public}) { }
+function a4([while, for, public]){ }
+function a5(...while) { }
+function a6(...public) { }
+function a7(...a: string) { }
+a({ while: 1 });
-function a3({x: { y, z}, j: {k: {a}} }) {
- return [y, z, a];
-}
+// No Error
+function b1({public: x}) { }
+function b2({while: y}) { }
+b1({ public: 1 });
+b2({ while: 1 });
-function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] {
- return [y, z, a];
-}
-
-function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] {
- return [y, z, a];
-}
//// [destructuringParameterDeclaration3.js]
+// A parameter declaration may specify either an identifier or a binding pattern.
+// Reserved words are not allowed to be used as an identifier in parameter declaration
+"use strict";
+// Error
function a(_a) {
- var x = _a[0], _b = _a[1], y = _b[0], z = _b[1], j = _a[2][0][0];
- return [x, y, z, j];
+ var while = _a.while;
}
function a1(_a) {
- var x = _a.slice(0);
- return [x];
+ var public = _a.public;
}
-function a2(_a) {
- var public = (_a === void 0 ? { "public": "1" } : _a).public;
- return public;
+while (, )
+ for (, public; ; )
+ ;
+{ }
+while () { }
+function a6() {
+ var public = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ public[_i - 0] = arguments[_i];
+ }
}
-function a3(_a) {
- var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a;
- return [y, z, a];
+function a7() {
+ var a = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ a[_i - 0] = arguments[_i];
+ }
}
-function a4(_a) {
- var _b = _a === void 0 ? { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : _a, _c = _b.x, y = _c.y, z = _c.z, a = _b.j.k.a;
- return [y, z, a];
+a({ while: 1 });
+// No Error
+function b1(_a) {
+ var x = _a.public;
}
-function a5(_a) {
- var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a;
- return [y, z, a];
+function b2(_a) {
+ var y = _a.while;
}
+b1({ public: 1 });
+b2({ while: 1 });
diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.types b/tests/baselines/reference/destructuringParameterDeclaration3.types
deleted file mode 100644
index 41835d9e456..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration3.types
+++ /dev/null
@@ -1,92 +0,0 @@
-=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts ===
-function a([x, [y, z], [[j]]]) {
->a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[]
->x : any
->y : any
->z : any
->j : any
-
- return [x, y, z, j];
->[x, y, z, j] : any[]
->x : any
->y : any
->z : any
->j : any
-}
-
-function a1([...x]) {
->a1 : ([...x]: any[]) => any[][]
->x : any[]
-
- return [x];
->[x] : any[][]
->x : any[]
-}
-
-function a2({public} = { "public": "1" }) {
->a2 : ({public}?: { "public": string; }) => string
->public : string
->{ "public": "1" } : { "public": string; }
-
- return public;
->public : string
-}
-
-function a3({x: { y, z}, j: {k: {a}} }) {
->a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[]
->x : unknown
->y : any
->z : any
->j : unknown
->k : unknown
->a : any
-
- return [y, z, a];
->[y, z, a] : any[]
->y : any
->z : any
->a : any
-}
-
-function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] {
->a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[]
->x : unknown
->y : number
->z : number
->j : unknown
->k : unknown
->a : string
->{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; }
->x : { y: number; z: number; }
->{ y: 1, z: 1 } : { y: number; z: number; }
->y : number
->z : number
->j : { k: { a: string; }; }
->{ k: { a: "hello" } } : { k: { a: string; }; }
->k : { a: string; }
->{ a: "hello" } : { a: string; }
->a : string
-
- return [y, z, a];
->[y, z, a] : (string | number)[]
->y : number
->z : number
->a : string
-}
-
-function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] {
->a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[]
->x : unknown
->y : any
->z : any
->j : unknown
->k : unknown
->a : any
-
- return [y, z, a];
->[y, z, a] : any[]
->y : any
->z : any
->a : any
-}
-
diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js
deleted file mode 100644
index e129140f3f2..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js
+++ /dev/null
@@ -1,45 +0,0 @@
-//// [destructuringParameterDeclaration3ES6.ts]
-function a([x, [y, z], [[j]]]) {
- return [x, y, z, j];
-}
-
-function a1([...x]) {
- return [x];
-}
-
-function a2({public} = { "public": "1" }) {
- return public;
-}
-
-function a3({x: { y, z}, j: {k: {a}} }) {
- return [y, z, a];
-}
-
-function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] {
- return [y, z, a];
-}
-
-function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] {
- return [y, z, a];
-}
-
-
-//// [destructuringParameterDeclaration3ES6.js]
-function a([x, [y, z], [[j]]]) {
- return [x, y, z, j];
-}
-function a1([...x]) {
- return [x];
-}
-function a2({ public } = { "public": "1" }) {
- return public;
-}
-function a3({ x: { y, z }, j: { k: { a } } }) {
- return [y, z, a];
-}
-function a4({ x: { y, z }, j: { k: { a } } } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }) {
- return [y, z, a];
-}
-function a5({ x: { y, z }, j: { k: { a } } }) {
- return [y, z, a];
-}
diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types
deleted file mode 100644
index 01c67e1e547..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types
+++ /dev/null
@@ -1,92 +0,0 @@
-=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts ===
-function a([x, [y, z], [[j]]]) {
->a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[]
->x : any
->y : any
->z : any
->j : any
-
- return [x, y, z, j];
->[x, y, z, j] : any[]
->x : any
->y : any
->z : any
->j : any
-}
-
-function a1([...x]) {
->a1 : ([...x]: Iterable) => any[][]
->x : any[]
-
- return [x];
->[x] : any[][]
->x : any[]
-}
-
-function a2({public} = { "public": "1" }) {
->a2 : ({public}?: { "public": string; }) => string
->public : string
->{ "public": "1" } : { "public": string; }
-
- return public;
->public : string
-}
-
-function a3({x: { y, z}, j: {k: {a}} }) {
->a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[]
->x : unknown
->y : any
->z : any
->j : unknown
->k : unknown
->a : any
-
- return [y, z, a];
->[y, z, a] : any[]
->y : any
->z : any
->a : any
-}
-
-function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] {
->a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[]
->x : unknown
->y : number
->z : number
->j : unknown
->k : unknown
->a : string
->{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; }
->x : { y: number; z: number; }
->{ y: 1, z: 1 } : { y: number; z: number; }
->y : number
->z : number
->j : { k: { a: string; }; }
->{ k: { a: "hello" } } : { k: { a: string; }; }
->k : { a: string; }
->{ a: "hello" } : { a: string; }
->a : string
-
- return [y, z, a];
->[y, z, a] : (string | number)[]
->y : number
->z : number
->a : string
-}
-
-function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] {
->a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[]
->x : unknown
->y : any
->z : any
->j : unknown
->k : unknown
->a : any
-
- return [y, z, a];
->[y, z, a] : any[]
->y : any
->z : any
->a : any
-}
-
diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt
index cf4b15d1271..d5d0888e632 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt
+++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt
@@ -1,27 +1,78 @@
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
- Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(46,4): error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'.
+ Types of property 'y' are incompatible.
+ Type 'Class' is not assignable to type 'D'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(47,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'.
+ Property 'y' is missing in type '{}'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(48,4): error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'.
+ Types of property 'y' are incompatible.
+ Type 'number' is not assignable to type 'D'.
+tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(49,4): error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'.
+ Types of property 'y' are incompatible.
+ Type 'string' is not assignable to type 'D'.
-==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (1 errors) ====
+==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (4 errors) ====
+ // Parameter with generic
interface F { }
- class C implements F{
+ class Class implements F {
+ constructor() { }
}
- function foo(...a: T[]) { }
- function foo1(...a: T[]) { }
- function bar({x} = { x: new C() }) { }
- function baz({x}: { x: F }) { }
- function baz1({x}: { x: C }) { }
- function baz2({x}: { x: C }) { }
- var obj = new C();
- baz1({ x: obj });
- baz({ x: new C() });
- baz({ x: {} });
- foo("hello", 1, 2);
- ~~~
-!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
-!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
- foo("hello", 1, 2);
- foo("hello", "world");
+ class SubClass extends Class {
+ foo: boolean;
+ constructor() { super(); }
+ }
-
\ No newline at end of file
+ class D implements F {
+ foo: boolean
+ constructor() { }
+ }
+
+ class SubD extends D {
+ bar: number
+ constructor() {
+ super();
+ }
+ }
+
+
+ function d0({x} = { x: new Class() }) { }
+ function d1({x}: { x: F }) { }
+ function d2({x}: { x: Class }) { }
+ function d3({y}: { y: D }) { }
+ function d4({y} = { y: new D() }) { }
+
+ var obj = new Class();
+ d0({ x: 1 });
+ d0({ x: {} });
+ d0({ x: "string" });
+
+ d1({ x: new Class() });
+ d1({ x: {} });
+ d1({ x: "string" });
+
+ d2({ x: new SubClass() });
+ d2({ x: {} });
+
+ d3({ y: new SubD() });
+ d3({ y: new SubClass() });
+ // Error
+ d3({ y: new Class() });
+ ~~~~~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'.
+!!! error TS2345: Types of property 'y' are incompatible.
+!!! error TS2345: Type 'Class' is not assignable to type 'D'.
+ d3({});
+ ~~
+!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'.
+!!! error TS2345: Property 'y' is missing in type '{}'.
+ d3({ y: 1 });
+ ~~~~~~~~
+!!! error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'.
+!!! error TS2345: Types of property 'y' are incompatible.
+!!! error TS2345: Type 'number' is not assignable to type 'D'.
+ d3({ y: "world" });
+ ~~~~~~~~~~~~~~
+!!! error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'.
+!!! error TS2345: Types of property 'y' are incompatible.
+!!! error TS2345: Type 'string' is not assignable to type 'D'.
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.js b/tests/baselines/reference/destructuringParameterDeclaration4.js
index 3f83402dffa..3eb0b3f8c19 100644
--- a/tests/baselines/reference/destructuringParameterDeclaration4.js
+++ b/tests/baselines/reference/destructuringParameterDeclaration4.js
@@ -1,58 +1,113 @@
//// [destructuringParameterDeclaration4.ts]
+// Parameter with generic
interface F { }
-class C implements F{
+class Class implements F {
+ constructor() { }
}
-function foo(...a: T[]) { }
-function foo1(...a: T[]) { }
-function bar({x} = { x: new C() }) { }
-function baz({x}: { x: F }) { }
-function baz1({x}: { x: C }) { }
-function baz2({x}: { x: C }) { }
-var obj = new C();
-baz1({ x: obj });
-baz({ x: new C() });
-baz({ x: {} });
-foo("hello", 1, 2);
-foo("hello", 1, 2);
-foo("hello", "world");
+class SubClass extends Class {
+ foo: boolean;
+ constructor() { super(); }
+}
-
+class D implements F {
+ foo: boolean
+ constructor() { }
+}
+
+class SubD extends D {
+ bar: number
+ constructor() {
+ super();
+ }
+}
+
+
+function d0({x} = { x: new Class() }) { }
+function d1({x}: { x: F }) { }
+function d2({x}: { x: Class }) { }
+function d3({y}: { y: D }) { }
+function d4({y} = { y: new D() }) { }
+
+var obj = new Class();
+d0({ x: 1 });
+d0({ x: {} });
+d0({ x: "string" });
+
+d1({ x: new Class() });
+d1({ x: {} });
+d1({ x: "string" });
+
+d2({ x: new SubClass() });
+d2({ x: {} });
+
+d3({ y: new SubD() });
+d3({ y: new SubClass() });
+// Error
+d3({ y: new Class() });
+d3({});
+d3({ y: 1 });
+d3({ y: "world" });
//// [destructuringParameterDeclaration4.js]
-var C = (function () {
- function C() {
+var __extends = this.__extends || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Class = (function () {
+ function Class() {
}
- return C;
+ return Class;
})();
-function foo() {
- var a = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- a[_i - 0] = arguments[_i];
+var SubClass = (function (_super) {
+ __extends(SubClass, _super);
+ function SubClass() {
+ _super.call(this);
}
-}
-function foo1() {
- var a = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- a[_i - 0] = arguments[_i];
+ return SubClass;
+})(Class);
+var D = (function () {
+ function D() {
}
+ return D;
+})();
+var SubD = (function (_super) {
+ __extends(SubD, _super);
+ function SubD() {
+ _super.call(this);
+ }
+ return SubD;
+})(D);
+function d0(_a) {
+ var x = (_a === void 0 ? { x: new Class() } : _a).x;
}
-function bar(_a) {
- var x = (_a === void 0 ? { x: new C() } : _a).x;
-}
-function baz(_a) {
+function d1(_a) {
var x = _a.x;
}
-function baz1(_a) {
+function d2(_a) {
var x = _a.x;
}
-function baz2(_a) {
- var x = _a.x;
+function d3(_a) {
+ var y = _a.y;
}
-var obj = new C();
-baz1({ x: obj });
-baz({ x: new C() });
-baz({ x: {} });
-foo("hello", 1, 2);
-foo("hello", 1, 2);
-foo("hello", "world");
+function d4(_a) {
+ var y = (_a === void 0 ? { y: new D() } : _a).y;
+}
+var obj = new Class();
+d0({ x: 1 });
+d0({ x: {} });
+d0({ x: "string" });
+d1({ x: new Class() });
+d1({ x: {} });
+d1({ x: "string" });
+d2({ x: new SubClass() });
+d2({ x: {} });
+d3({ y: new SubD() });
+d3({ y: new SubClass() });
+// Error
+d3({ y: new Class() });
+d3({});
+d3({ y: 1 });
+d3({ y: "world" });
diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt
deleted file mode 100644
index 21cd9f36c0f..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'.
- Property 'z' is missing in type '{}'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,14): error TS2300: Duplicate identifier 'z'.
-tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,18): error TS2300: Duplicate identifier 'z'.
-
-
-==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts (4 errors) ====
- enum Foo { a }
- function a({x, a}: { x: number, a: number }) { }
- function a1({z: {x, y: {j}}}) { }
- function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
- function a3({z} = {z:10}) { }
- function a4({z=10}) { }
- function a6({b}: { b: number|string|boolean } = { b: "hello" }) { }
- a2();
- a2({ z: { x: "hello" , y: { j: Foo.a } }});
- a3();
- a3({ z: Foo.a });
- a4({});
- a6({ b: 10 });
- a6({ b: true });
-
- // error
- a4();
- ~~~~
-!!! error TS2346: Supplied parameters do not match any signature of call target.
- a3({});
- ~~
-!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'.
-!!! error TS2345: Property 'z' is missing in type '{}'.
- function a5([z], z: number) { }
- ~
-!!! error TS2300: Duplicate identifier 'z'.
- ~
-!!! error TS2300: Duplicate identifier 'z'.
-
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.js b/tests/baselines/reference/destructuringParameterDeclarationES6.js
deleted file mode 100644
index 7a4c929003d..00000000000
--- a/tests/baselines/reference/destructuringParameterDeclarationES6.js
+++ /dev/null
@@ -1,44 +0,0 @@
-//// [destructuringParameterDeclarationES6.ts]
-enum Foo { a }
-function a({x, a}: { x: number, a: number }) { }
-function a1({z: {x, y: {j}}}) { }
-function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
-function a3({z} = {z:10}) { }
-function a4({z=10}) { }
-function a6({b}: { b: number|string|boolean } = { b: "hello" }) { }
-a2();
-a2({ z: { x: "hello" , y: { j: Foo.a } }});
-a3();
-a3({ z: Foo.a });
-a4({});
-a6({ b: 10 });
-a6({ b: true });
-
-// error
-a4();
-a3({});
-function a5([z], z: number) { }
-
-
-//// [destructuringParameterDeclarationES6.js]
-var Foo;
-(function (Foo) {
- Foo[Foo["a"] = 0] = "a";
-})(Foo || (Foo = {}));
-function a({ x, a }) { }
-function a1({ z: { x, y: { j } } }) { }
-function a2({ z: { x, y: { j } } } = { z: { x: "hi", y: { j: 1 } } }) { }
-function a3({ z } = { z: 10 }) { }
-function a4({ z = 10 }) { }
-function a6({ b } = { b: "hello" }) { }
-a2();
-a2({ z: { x: "hello", y: { j: Foo.a } } });
-a3();
-a3({ z: Foo.a });
-a4({});
-a6({ b: 10 });
-a6({ b: true });
-// error
-a4();
-a3({});
-function a5([z], z) { }
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts
deleted file mode 100644
index c840dba2d2b..00000000000
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-enum Foo { a }
-function a({x, a}: { x: number, a: number }) { }
-function a1({z: {x, y: {j}}}) { }
-function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
-function a3({z} = {z:10}) { }
-function a4({z=10}) { }
-function a6({b}: { b: number|string|boolean } = { b: "hello" }) { }
-a2();
-a2({ z: { x: "hello" , y: { j: Foo.a } }});
-a3();
-a3({ z: Foo.a });
-a4({});
-a6({ b: 10 });
-a6({ b: true });
-
-// error
-a4();
-a3({});
-function a5([z], z: number) { }
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts
index 6e9579926dd..027d11b8c2f 100644
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts
+++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts
@@ -1,21 +1,106 @@
-type arrayString = Array
-type someArray = Array | number[];
-type stringOrNumArray = Array;
+// A parameter declaration may specify either an identifier or a binding pattern.
+// The identifiers specified in parameter declarations and binding patterns
+// in a parameter list must be unique within that parameter list.
-function a3(...x = [1,2,3]) { }
-function a4(...x: (number|string)[]) { }
-function a5(...a) { }
-function a6(...a: Array) { }
-function a7(...a: arrayString) { }
-function a8(...a: stringOrNumArray) { }
-function a9(...a: someArray) { }
-function a10(...b?) { }
-function a11(...b = [1,2,3]) { }
+// If the declaration includes a type annotation, the parameter is of that type
+function a0(x: number, y: string, z: boolean) { }
+function a1([a, b, [[c]]]: [number, number, string[][]]) { }
+function a2(o: { x: number, a: number }) { }
+function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { };
+function a1({x, a}: { x: number, a: number }) { }
+
+a1([1, 2, [["world"]]]);
+a1([1, 2, [["world"]], 3]);
+a1([1, "string", [["world"]]); // Error
+a1([1, 2, [["world"]], "string"]); // Error
+
+
+// If the declaration includes an initializer expression (which is permitted only
+// when the parameter list occurs in conjunction with a function body),
+// the parameter type is the widened form (section 3.11) of the type of the initializer expression.
+
+function b1(z = 10, y = 60, u = () => true) { }
+function b2(z = [undefined, null]) { };
+function b3(z = null, o = { x: 0, y: undefined }) { }
+function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
+
+interface F1 {
+ b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body
+ b6(z, y, [, a, b], {p, m: { q, r}});
+}
+
+b2([1, 2, 3]); // z is widen to the type any[]
+b3("string", { x: 200, y: "string" });
+b3("string", { x: 200, y: true });
+b3("string", { x: "string", y: true }); // Error
+
+
+// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
+enum Foo { a }
+function c0({z: {x, y: {j}}}) { }
+function c1({z} = { z: 10 }) { }
+function c2({z = 10}) { }
+function c3({b}: { b: number|string} = { b: "hello" }) { }
+function c4([z], z: number) { } // Duplicate identifier
+function c5([a, b, [[c]]]) { }
+function c6([a, b, [[c=1]]]) { }
+
+c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} }
+c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} }
+c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} }
+
+c1({}); // Error, implied type is {z:number}?
+c1({ z: true }); // Error, implied type is {z:number}?
+c1(); // Implied type is {z:number}?
+c1({ z: 1 }) // Implied type is {z:number}?
+
+c2({}); // Implied type is {z?: number}
+c2({z:1}); // Implied type is {z?: number}
+c2({z:false}); // Error, implied type is {z?: number}
+
+c3({ b: 1 }); // Implied type is { b: number|string }.
+c3({ b: true }); // Error, implied type is { b: number|string }.
+
+c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
+c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
+c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
+
+c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
+
+// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
+// or by including an initializer.
+
+function d0(x?) { }
+function d0(x = 10) { }
+function d1([a, b, c]?) { }
+function d2({x, y, z}?) { }
+
+interface F2 {
+ d3([a, b, c]?);
+ d4({x, y, z}?);
+ e0([a, b, c]);
+}
+
+class C2 implements F2 {
+ constructor() { }
+ d3() { }
+ d4() { }
+ e0([a, b, c]) { }
+}
+
+class C3 implements F2 {
+ d3([a, b, c]) { }
+ d4({x, y, z}) { }
+ e0([a, b, c]) { }
+}
+
+class C4 implements F2 {
+ d3([a, b, c]?) { }
+ d4({x, y, c}) { }
+ e0([a, b, q]) { }
+}
+
+function d5({x, y} = { x: 1, y: 2 }) { }
+d5(); // Parameter is optional as its declaration included an initializer
-a4(1, 2, "hello", true);
-var array = [1, 2, 3];
-var array2 = [true, false, "hello"];
-a5([...array]);
-a4(...array);
-a4(...array2);
\ No newline at end of file
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts
deleted file mode 100644
index 1441226e061..00000000000
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-// @target: es6
-type arrayString = Array
-type someArray = Array | number[];
-type stringOrNumArray = Array;
-
-function a3(...x = [1,2,3]) { }
-function a4(...x: (number|string)[]) { }
-function a5(...a) { }
-function a6(...a: Array) { }
-function a7(...a: arrayString) { }
-function a8(...a: stringOrNumArray) { }
-function a9(...a: someArray) { }
-function a10(...b?) { }
-function a11(...b = [1,2,3]) { }
-
-
-a4(1, 2, "hello", true);
-var array = [1, 2, 3];
-var array2 = [true, false, "hello"];
-a5([...array]);
-a4(...array);
-a4(...array2);
\ No newline at end of file
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts
index 59763c95902..5a775eb69c9 100644
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts
+++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts
@@ -1,19 +1,61 @@
-"use strict"
-function a({while}) { }
-function a1({public}) { }
-function a2({public: x}) { }
-function a3({while: y}) { }
-function a4([while, for, public]){ }
-function a5(...while) { }
-function a6(...public) { }
-function a7(...a: string) { }
+// If the parameter is a rest parameter, the parameter type is any[]
+// A type annotation for a rest parameter must denote an array type.
+
+// RestParameter:
+// ... Identifier TypeAnnotation(opt)
+
+type arrayString = Array
+type someArray = Array | number[];
+type stringOrNumArray = Array;
+
+function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type
+function a1(...x: (number|string)[]) { }
+function a2(...a) { }
+function a3(...a: Array) { }
+function a4(...a: arrayString) { }
+function a5(...a: stringOrNumArray) { }
+function a6(...a: someArray) { } // Error, rest parameter must be array type
+function a7(...b?) { } // Error, can't be optional
+function a8(...b = [1,2,3]) { } // Error, can't have initializer
+function a9([a, b, [[c]]]) { }
+function a10([a, b, [[c]], ...x]) { }
+function a11([a, b, c, ...x]: number[]) { }
+
+
+a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
+var array = [1, 2, 3];
+var array2 = [true, false, "hello"];
+a2([...array]);
+a1(...array);
+a1(...array2); // Error parameter type is (number|string)[]
+
+a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
+a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
+a9([1, 2]); // Error, parameter type is [any, any, [[any]]]
+
+a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
+a10([1, 2, 3, false, true]); // Parameter type is any[]
+a10([1, 2]); // Parameter type is any[]
+
+a11([1, 2]); // Parameter type is number[]
+a11([1, 2, "string"]); // Error, parameter type is number[]
+
class C {
- constructor(public ...a) { }
+ constructor(public ...a) { } // Rest parameter can't have accessibilityModifier
}
+// Rest parameter with generic
+function foo(...a: T[]) { }
+foo("hello", 1, 2); // Error
+foo("hello", 1, 2);
+foo("hello", "world");
+
+enum E { a, b }
+const enum E1 { a, b }
+function foo1(...a: T[]) { }
+foo1(1, 2, 3, E.a);
+foo1(1, 2, 3, E1.a, E.b);
+foo1(1, 2, "string", E1.a, E.b); // Error
-a2({ public: 1 });
-a3({ while: 1 });
-a({ while: 1 });
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts
deleted file mode 100644
index e50a455d824..00000000000
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-//@target: es6
-"use strict"
-function a({while}) { }
-function a1({public}) { }
-function a2({public: x}) { }
-function a3({while: y}) { }
-function a4([while, for, public]){ }
-function a5(...while) { }
-function a6(...public) { }
-function a7(...a: string) { }
-
-class C {
- constructor(public ...a) { }
-}
-
-
-a2({ public: 1 });
-a3({ while: 1 });
-a({ while: 1 });
-
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts
index 96fc87c6c86..c583b750fef 100644
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts
+++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts
@@ -1,23 +1,20 @@
-function a([x, [y, z], [[j]]]) {
- return [x, y, z, j];
-}
+// A parameter declaration may specify either an identifier or a binding pattern.
-function a1([...x]) {
- return [x];
-}
+// Reserved words are not allowed to be used as an identifier in parameter declaration
+"use strict"
-function a2({public} = { "public": "1" }) {
- return public;
-}
+// Error
+function a({while}) { }
+function a1({public}) { }
+function a4([while, for, public]){ }
+function a5(...while) { }
+function a6(...public) { }
+function a7(...a: string) { }
+a({ while: 1 });
-function a3({x: { y, z}, j: {k: {a}} }) {
- return [y, z, a];
-}
+// No Error
+function b1({public: x}) { }
+function b2({while: y}) { }
+b1({ public: 1 });
+b2({ while: 1 });
-function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] {
- return [y, z, a];
-}
-
-function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] {
- return [y, z, a];
-}
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts
deleted file mode 100644
index 7c50917ebe5..00000000000
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-// @target: es6
-function a([x, [y, z], [[j]]]) {
- return [x, y, z, j];
-}
-
-function a1([...x]) {
- return [x];
-}
-
-function a2({public} = { "public": "1" }) {
- return public;
-}
-
-function a3({x: { y, z}, j: {k: {a}} }) {
- return [y, z, a];
-}
-
-function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] {
- return [y, z, a];
-}
-
-function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] {
- return [y, z, a];
-}
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts
index b59c539d672..4f0f52d3065 100644
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts
+++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts
@@ -1,18 +1,49 @@
-interface F { }
-class C implements F{
+// Parameter with generic
+interface F { }
+class Class implements F {
+ constructor() { }
}
-function foo(...a: T[]) { }
-function foo1(...a: T[]) { }
-function bar({x} = { x: new C() }) { }
-function baz({x}: { x: F }) { }
-function baz1({x}: { x: C }) { }
-function baz2({x}: { x: C }) { }
-var obj = new C();
-baz1({ x: obj });
-baz({ x: new C() });
-baz({ x: {} });
-foo("hello", 1, 2);
-foo("hello", 1, 2);
-foo("hello", "world");
+class SubClass extends Class {
+ foo: boolean;
+ constructor() { super(); }
+}
+class D implements F {
+ foo: boolean
+ constructor() { }
+}
+
+class SubD extends D {
+ bar: number
+ constructor() {
+ super();
+ }
+}
+
+
+function d0({x} = { x: new Class() }) { }
+function d1({x}: { x: F }) { }
+function d2({x}: { x: Class }) { }
+function d3({y}: { y: D }) { }
+function d4({y} = { y: new D() }) { }
+
+var obj = new Class();
+d0({ x: 1 });
+d0({ x: {} });
+d0({ x: "string" });
+
+d1({ x: new Class() });
+d1({ x: {} });
+d1({ x: "string" });
+
+d2({ x: new SubClass() });
+d2({ x: {} });
+
+d3({ y: new SubD() });
+d3({ y: new SubClass() });
+// Error
+d3({ y: new Class() });
+d3({});
+d3({ y: 1 });
+d3({ y: "world" });
\ No newline at end of file
diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts
deleted file mode 100644
index 0d359421851..00000000000
--- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-//@target: es6
-enum Foo { a }
-function a({x, a}: { x: number, a: number }) { }
-function a1({z: {x, y: {j}}}) { }
-function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
-function a3({z} = {z:10}) { }
-function a4({z=10}) { }
-function a6({b}: { b: number|string|boolean } = { b: "hello" }) { }
-a2();
-a2({ z: { x: "hello" , y: { j: Foo.a } }});
-a3();
-a3({ z: Foo.a });
-a4({});
-a6({ b: 10 });
-a6({ b: true });
-
-// error
-a4();
-a3({});
-function a5([z], z: number) { }