diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 79a5a696ef4..f3e9c325da6 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -1,5 +1,6 @@ // /// +/* @internal */ module ts { export var Diagnostics = { Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." }, diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt deleted file mode 100644 index 078895d07b0..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt +++ /dev/null @@ -1,272 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,4): error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. - Types of property '1' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,29): error TS1005: ',' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. - Types of property 'pop' are incompatible. - Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. - Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. - Type 'string' is not assignable to type 'number | string[][]'. - Type 'string' is not assignable to type 'string[][]'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(26,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(26,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(36,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(37,4): error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'undefined'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(38,4): error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. - Types of property '0' are incompatible. - Type '[string]' is not assignable to type '[undefined]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'undefined'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(47,14): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(47,18): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(53,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(55,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(56,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 '{ 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(65,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(69,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(71,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(76,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(77,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(78,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(79,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(100,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(101,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. - - -==== 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. - - // If the declaration includes a type annotation, the parameter is of that type - 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 a4({x, a}: { x: number, a: number }) { } - - a1([1, 2, [["world"]]]); - a1([1, 2, [["world"]], 3]); - a1([1, "string", [["world"]]); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. -!!! error TS2345: Types of property '1' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'number'. - ~ -!!! error TS1005: ',' expected. - a1([1, 2, [["world"]], "string"]); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. -!!! error TS2345: Types of property 'pop' are incompatible. -!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. -!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. -!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. -!!! error TS2345: Type 'string' is not assignable to type 'string[][]'. - - - // 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 = [undefined, null]) { }; - function b2(z = null, o = { x: 0, y: undefined }) { } - function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } - - interface F1 { - b4(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. - b5(z, y, [, a, b], {p, m: { q, r}}); - } - - function b6([a, z, y] = [undefined, null, undefined]) { } - function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } - - b1([1, 2, 3]); // z is widen to the type any[] - b2("string", { x: 200, y: "string" }); - b2("string", { x: 200, y: true }); - b2("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'. - b6(["string", 1, 2]); // Shouldn't be an error - ~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'undefined'. - b7([["string"], 1, [[true, false]]]); // Shouldn't be an error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type '[string]' is not assignable to type '[undefined]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'undefined'. - - - // 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 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; }; }'. - - 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 '{ 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, binding pattern can't be optional in implementation signature - ~~~~~~~~~~ -!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. - function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature - ~~~~~~~~~~ -!!! 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 - - // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, - // as such annotations would conflict with the already established meaning of colons in object literals. - // Type annotations must instead be written on the top- level parameter declaration - - function e1({x: number}) { } // x has type any NOT number - function e2({x}: { x: number }) { } // x is type number - function e3({x}: { x?: number }) { } // x is an optional with type number - function e4({x: [number,string,any] }) { } // x has type [any, any, any] - function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] - - function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; - - - \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt new file mode 100644 index 00000000000..269d2b5640d --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt @@ -0,0 +1,124 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(32,4): error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(33,4): error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. + Types of property '0' are incompatible. + Type '[string]' is not assignable to type '[undefined]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(62,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(63,10): error TS2393: Duplicate function implementation. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts (4 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. + + // If the declaration includes a type annotation, the parameter is of that type + 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 a4({x, a}: { x: number, a: number }) { } + + a1([1, 2, [["world"]]]); + a1([1, 2, [["world"]], 3]); + + // 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 = [undefined, null]) { }; + function b2(z = null, o = { x: 0, y: undefined }) { } + function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + + interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); + } + + function b6([a, z, y] = [undefined, null, undefined]) { } + function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + + b1([1, 2, 3]); // z is widen to the type any[] + b2("string", { x: 200, y: "string" }); + b2("string", { x: 200, y: true }); + b6(["string", 1, 2]); // Shouldn't be an error + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'undefined'. + b7([["string"], 1, [[true, false]]]); // Shouldn't be an error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type '[string]' is not assignable to type '[undefined]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'undefined'. + + + // 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 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}} } + + 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} + + c3({ b: 1 }); // 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]]] + + // 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. + + 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]) { } + } + + + function d5({x, y} = { x: 1, y: 2 }) { } + d5(); // Parameter is optional as its declaration included an initializer + + // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, + // as such annotations would conflict with the already established meaning of colons in object literals. + // Type annotations must instead be written on the top- level parameter declaration + + function e1({x: number}) { } // x has type any NOT number + function e2({x}: { x: number }) { } // x is type number + function e3({x}: { x?: number }) { } // x is an optional with type number + function e4({x: [number,string,any] }) { } // x has type [any, any, any] + function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.js b/tests/baselines/reference/destructuringParameterDeclaration1ES5.js similarity index 74% rename from tests/baselines/reference/destructuringParameterDeclaration1.js rename to tests/baselines/reference/destructuringParameterDeclaration1ES5.js index 0d8590ae50a..9a5b4eb8156 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1.js +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.js @@ -1,4 +1,4 @@ -//// [destructuringParameterDeclaration1.ts] +//// [destructuringParameterDeclaration1ES5.ts] // 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. @@ -11,9 +11,6 @@ function a4({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), @@ -24,7 +21,6 @@ function b2(z = null, o = { x: 0, y: undefined }) { } function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } interface F1 { - b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body b5(z, y, [, a, b], {p, m: { q, r}}); } @@ -34,7 +30,6 @@ function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined b1([1, 2, 3]); // z is widen to the type any[] b2("string", { x: 200, y: "string" }); b2("string", { x: 200, y: true }); -b2("string", { x: "string", y: true }); // Error b6(["string", 1, 2]); // Shouldn't be an error b7([["string"], 1, [[true, false]]]); // Shouldn't be an error @@ -45,39 +40,28 @@ 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]?) { } // Error, binding pattern can't be optional in implementation signature -function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature interface F2 { d3([a, b, c]?); @@ -98,11 +82,6 @@ class C3 implements F2 { 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 @@ -116,13 +95,9 @@ function e2({x}: { x: number }) { } // x is type number function e3({x}: { x?: number }) { } // x is an optional with type number function e4({x: [number,string,any] }) { } // x has type [any, any, any] function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] - -function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; - - -//// [destructuringParameterDeclaration1.js] +//// [destructuringParameterDeclaration1ES5.js] // 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. @@ -140,8 +115,6 @@ function a4(_a) { } 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. @@ -165,7 +138,6 @@ function b7(_a) { b1([1, 2, 3]); // z is widen to the type any[] b2("string", { x: 200, y: "string" }); b2("string", { x: 200, y: true }); -b2("string", { x: "string", y: true }); // Error b6(["string", 1, 2]); // Shouldn't be an error b7([["string"], 1, [[true, false]]]); // Shouldn't be an error // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) @@ -185,9 +157,6 @@ function c2(_a) { 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]; } @@ -196,32 +165,19 @@ function c6(_a) { } 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]; -} // Error, binding pattern can't be optional in implementation signature -function d2(_a) { - var x = _a.x, y = _a.y, z = _a.z; -} // Error, binding pattern can't be optional in implementation signature var C2 = (function () { function C2() { } @@ -246,20 +202,6 @@ var C3 = (function () { }; 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; } @@ -282,6 +224,3 @@ function e4(_a) { function e5(_a) { var _b = _a.x, a = _b[0], b = _b[1], c = _b[2]; } // x has type [any, any, any] -function e6(_a) { - var _b = _a.x, number = _b[0], number = _b[1], number = _b[2]; -} // should be an error, duplicate identifier; diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols b/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols new file mode 100644 index 00000000000..3267d4470db --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols @@ -0,0 +1,314 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts === +// Conformance for emitting ES6 + +// 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 a1([a, b, [[c]]]: [number, number, string[][]]) { } +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 7, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 7, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 7, 21)) + +function a2(o: { x: number, a: number }) { } +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration1ES6.ts, 7, 60)) +>o : Symbol(o, Decl(destructuringParameterDeclaration1ES6.ts, 8, 12)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 8, 16)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 8, 27)) + +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +>a3 : Symbol(a3, Decl(destructuringParameterDeclaration1ES6.ts, 8, 44)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 9, 13)) +>k : Symbol(k, Decl(destructuringParameterDeclaration1ES6.ts, 9, 15)) +>m : Symbol(m, Decl(destructuringParameterDeclaration1ES6.ts, 9, 23)) +>n : Symbol(n, Decl(destructuringParameterDeclaration1ES6.ts, 9, 25)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 9, 34)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 9, 36)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 9, 39)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 9, 46)) +>k : Symbol(k, Decl(destructuringParameterDeclaration1ES6.ts, 9, 57)) +>l : Symbol(l, Decl(destructuringParameterDeclaration1ES6.ts, 9, 68)) +>m : Symbol(m, Decl(destructuringParameterDeclaration1ES6.ts, 9, 73)) +>n : Symbol(n, Decl(destructuringParameterDeclaration1ES6.ts, 9, 85)) +>q : Symbol(q, Decl(destructuringParameterDeclaration1ES6.ts, 9, 98)) + +function a4({x, a}: { x: number, a: number }) { } +>a4 : Symbol(a4, Decl(destructuringParameterDeclaration1ES6.ts, 9, 127)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 10, 13)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 10, 15)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 10, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 10, 32)) + +a1([1, 2, [["world"]]]); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) + +a1([1, 2, [["world"]], 3]); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) + + +// 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 = [undefined, null]) { }; +>b1 : Symbol(b1, Decl(destructuringParameterDeclaration1ES6.ts, 13, 27)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 20, 12)) +>undefined : Symbol(undefined) + +function b2(z = null, o = { x: 0, y: undefined }) { } +>b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 21, 12)) +>o : Symbol(o, Decl(destructuringParameterDeclaration1ES6.ts, 21, 21)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 21, 27)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 21, 33)) +>undefined : Symbol(undefined) + +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +>b3 : Symbol(b3, Decl(destructuringParameterDeclaration1ES6.ts, 21, 53)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 22, 17)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 22, 24)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 22, 32)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 22, 37)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 22, 46)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 22, 51)) + +interface F1 { +>F1 : Symbol(F1, Decl(destructuringParameterDeclaration1ES6.ts, 22, 67)) + + b5(z, y, [, a, b], {p, m: { q, r}}); +>b5 : Symbol(b5, Decl(destructuringParameterDeclaration1ES6.ts, 24, 14)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 25, 7)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 25, 9)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 25, 15)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 25, 18)) +>p : Symbol(p, Decl(destructuringParameterDeclaration1ES6.ts, 25, 24)) +>q : Symbol(q, Decl(destructuringParameterDeclaration1ES6.ts, 25, 31)) +>r : Symbol(r, Decl(destructuringParameterDeclaration1ES6.ts, 25, 34)) +} + +function b6([a, z, y] = [undefined, null, undefined]) { } +>b6 : Symbol(b6, Decl(destructuringParameterDeclaration1ES6.ts, 26, 1)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 28, 13)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 28, 15)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 28, 18)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } +>b7 : Symbol(b7, Decl(destructuringParameterDeclaration1ES6.ts, 28, 57)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 29, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 29, 17)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 29, 23)) +>d : Symbol(d, Decl(destructuringParameterDeclaration1ES6.ts, 29, 25)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +b1([1, 2, 3]); // z is widen to the type any[] +>b1 : Symbol(b1, Decl(destructuringParameterDeclaration1ES6.ts, 13, 27)) + +b2("string", { x: 200, y: "string" }); +>b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 32, 14)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 32, 22)) + +b2("string", { x: 200, y: true }); +>b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 33, 14)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 33, 22)) + + +// 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 } +>Foo : Symbol(Foo, Decl(destructuringParameterDeclaration1ES6.ts, 33, 34)) +>a : Symbol(Foo.a, Decl(destructuringParameterDeclaration1ES6.ts, 37, 10)) + +function c0({z: {x, y: {j}}}) { } +>c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 38, 17)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 38, 24)) + +function c1({z} = { z: 10 }) { } +>c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 39, 13)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 39, 19)) + +function c2({z = 10}) { } +>c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 40, 13)) + +function c3({b}: { b: number|string} = { b: "hello" }) { } +>c3 : Symbol(c3, Decl(destructuringParameterDeclaration1ES6.ts, 40, 25)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 18)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 40)) + +function c5([a, b, [[c]]]) { } +>c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 42, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 42, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 42, 21)) + +function c6([a, b, [[c=1]]]) { } +>c6 : Symbol(c6, Decl(destructuringParameterDeclaration1ES6.ts, 42, 30)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 43, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 43, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 43, 21)) + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +>c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 45, 4)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 45, 9)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 45, 15)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 45, 20)) + +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } +>c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 46, 4)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 46, 9)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 46, 22)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 46, 27)) + +c1(); // Implied type is {z:number}? +>c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) + +c1({ z: 1 }) // Implied type is {z:number}? +>c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 49, 4)) + +c2({}); // Implied type is {z?: number} +>c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) + +c2({z:1}); // Implied type is {z?: number} +>c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 52, 4)) + +c3({ b: 1 }); // Implied type is { b: number|string }. +>c3 : Symbol(c3, Decl(destructuringParameterDeclaration1ES6.ts, 40, 25)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 54, 4)) + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +>c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) + +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +>c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) + + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +interface F2 { +>F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) + + d3([a, b, c]?); +>d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 63, 14)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 64, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 64, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 64, 13)) + + d4({x, y, z}?); +>d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 64, 19)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 65, 8)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 65, 10)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 65, 13)) + + e0([a, b, c]); +>e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 65, 19)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 66, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 66, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 66, 13)) +} + +class C2 implements F2 { +>C2 : Symbol(C2, Decl(destructuringParameterDeclaration1ES6.ts, 67, 1)) +>F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) + + constructor() { } + d3() { } +>d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 70, 21)) + + d4() { } +>d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 71, 12)) + + e0([a, b, c]) { } +>e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 72, 12)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 73, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 73, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 73, 13)) +} + +class C3 implements F2 { +>C3 : Symbol(C3, Decl(destructuringParameterDeclaration1ES6.ts, 74, 1)) +>F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) + + d3([a, b, c]) { } +>d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 76, 24)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 77, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 77, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 77, 13)) + + d4({x, y, z}) { } +>d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 77, 21)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 78, 8)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 78, 10)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 78, 13)) + + e0([a, b, c]) { } +>e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 78, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 79, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 79, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 79, 13)) +} + +function d5({x, y} = { x: 1, y: 2 }) { } +>d5 : Symbol(d5, Decl(destructuringParameterDeclaration1ES6.ts, 80, 1)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 82, 13)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 82, 15)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 82, 22)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 82, 28)) + +d5(); // Parameter is optional as its declaration included an initializer +>d5 : Symbol(d5, Decl(destructuringParameterDeclaration1ES6.ts, 80, 1)) + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +>e1 : Symbol(e1, Decl(destructuringParameterDeclaration1ES6.ts, 83, 5)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 89, 13)) + +function e2({x}: { x: number }) { } // x is type number +>e2 : Symbol(e2, Decl(destructuringParameterDeclaration1ES6.ts, 89, 28)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 90, 13)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 90, 18)) + +function e3({x}: { x?: number }) { } // x is an optional with type number +>e3 : Symbol(e3, Decl(destructuringParameterDeclaration1ES6.ts, 90, 35)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 91, 13)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 91, 18)) + +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +>e4 : Symbol(e4, Decl(destructuringParameterDeclaration1ES6.ts, 91, 36)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 92, 17)) +>string : Symbol(string, Decl(destructuringParameterDeclaration1ES6.ts, 92, 24)) +>any : Symbol(any, Decl(destructuringParameterDeclaration1ES6.ts, 92, 31)) + +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] +>e5 : Symbol(e5, Decl(destructuringParameterDeclaration1ES6.ts, 92, 42)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 93, 17)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 93, 19)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 93, 22)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 93, 29)) + +function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; +>e6 : Symbol(e6, Decl(destructuringParameterDeclaration1ES6.ts, 93, 64)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index ed77f2dc92b..9395fa49b5b 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -22,10 +22,10 @@ function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boo >a3 : ({j, k, l: {m, n}, q: [a, b, c]}: { j: number; k: string; l: { m: boolean; n: number; }; q: (string | number)[]; }) => void >j : number >k : string ->l : unknown +>l : any >m : boolean >n : number ->q : unknown +>q : any >a : string | number >b : string | number >c : string | number @@ -47,15 +47,22 @@ a1([1, 2, [["world"]]]); >a1([1, 2, [["world"]]]) : void >a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void >[1, 2, [["world"]]] : [number, number, string[][]] +>1 : number +>2 : number >[["world"]] : string[][] >["world"] : string[] +>"world" : string a1([1, 2, [["world"]], 3]); >a1([1, 2, [["world"]], 3]) : void >a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void >[1, 2, [["world"]], 3] : [number, number, string[][], number] +>1 : number +>2 : number >[["world"]] : string[][] >["world"] : string[] +>"world" : string +>3 : number // If the declaration includes an initializer expression (which is permitted only @@ -67,29 +74,34 @@ function b1(z = [undefined, null]) { }; >z : any[] >[undefined, null] : null[] >undefined : undefined +>null : null function b2(z = null, o = { x: 0, y: undefined }) { } >b2 : (z?: any, o?: { x: number; y: any; }) => void >z : any +>null : null >o : { x: number; y: any; } >{ x: 0, y: undefined } : { x: number; y: undefined; } >x : number +>0 : number >y : undefined >undefined : undefined function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } >b3 : ({z: {x, y: {j}}}?: { z: { x: string; y: { j: number; }; }; }) => void ->z : unknown +>z : any >x : string ->y : unknown +>y : any >j : number >{ z: { x: "hi", y: { j: 1 } } } : { z: { x: string; y: { j: number; }; }; } >z : { x: string; y: { j: number; }; } >{ x: "hi", y: { j: 1 } } : { x: string; y: { j: number; }; } >x : string +>"hi" : string >y : { j: number; } >{ j: 1 } : { j: number; } >j : number +>1 : number interface F1 { >F1 : F1 @@ -98,10 +110,11 @@ interface F1 { >b5 : (z: any, y: any, [, a, b]: [any, any, any], {p, m: { q, r}}: { p: any; m: { q: any; r: any; }; }) => any >z : any >y : any +> : undefined >a : any >b : any >p : any ->m : unknown +>m : any >q : any >r : any } @@ -113,6 +126,7 @@ function b6([a, z, y] = [undefined, null, undefined]) { } >y : any >[undefined, null, undefined] : [undefined, null, undefined] >undefined : undefined +>null : null >undefined : undefined function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } @@ -134,20 +148,29 @@ b1([1, 2, 3]); // z is widen to the type any[] >b1([1, 2, 3]) : void >b1 : (z?: any[]) => void >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number b2("string", { x: 200, y: "string" }); >b2("string", { x: 200, y: "string" }) : void >b2 : (z?: any, o?: { x: number; y: any; }) => void +>"string" : string >{ x: 200, y: "string" } : { x: number; y: string; } >x : number +>200 : number >y : string +>"string" : string b2("string", { x: 200, y: true }); >b2("string", { x: 200, y: true }) : void >b2 : (z?: any, o?: { x: number; y: any; }) => void +>"string" : string >{ x: 200, y: true } : { x: number; y: boolean; } >x : number +>200 : number >y : boolean +>true : boolean // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) @@ -157,9 +180,9 @@ enum Foo { a } function c0({z: {x, y: {j}}}) { } >c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void ->z : unknown +>z : any >x : any ->y : unknown +>y : any >j : any function c1({z} = { z: 10 }) { } @@ -167,10 +190,12 @@ function c1({z} = { z: 10 }) { } >z : number >{ z: 10 } : { z: number; } >z : number +>10 : number function c2({z = 10}) { } >c2 : ({z = 10}: { z?: number; }) => void >z : number +>10 : number function c3({b}: { b: number|string} = { b: "hello" }) { } >c3 : ({b}?: { b: string | number; }) => void @@ -178,6 +203,7 @@ function c3({b}: { b: number|string} = { b: "hello" }) { } >b : string | number >{ b: "hello" } : { b: string; } >b : string +>"hello" : string function c5([a, b, [[c]]]) { } >c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void @@ -190,6 +216,7 @@ function c6([a, b, [[c=1]]]) { } >a : any >b : any >c : number +>1 : number c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } >c0({z : { x: 1, y: { j: "world" } }}) : void @@ -198,9 +225,11 @@ c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: >z : { x: number; y: { j: string; }; } >{ x: 1, y: { j: "world" } } : { x: number; y: { j: string; }; } >x : number +>1 : number >y : { j: string; } >{ j: "world" } : { j: string; } >j : string +>"world" : string c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } >c0({z : { x: "string", y: { j: true } }}) : void @@ -209,9 +238,11 @@ c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: >z : { x: string; y: { j: boolean; }; } >{ x: "string", y: { j: true } } : { x: string; y: { j: boolean; }; } >x : string +>"string" : string >y : { j: boolean; } >{ j: true } : { j: boolean; } >j : boolean +>true : boolean c1(); // Implied type is {z:number}? >c1() : void @@ -222,6 +253,7 @@ c1({ z: 1 }) // Implied type is {z:number}? >c1 : ({z}?: { z: number; }) => void >{ z: 1 } : { z: number; } >z : number +>1 : number c2({}); // Implied type is {z?: number} >c2({}) : void @@ -233,26 +265,36 @@ c2({z:1}); // Implied type is {z?: number} >c2 : ({z = 10}: { z?: number; }) => void >{z:1} : { z: number; } >z : number +>1 : number c3({ b: 1 }); // Implied type is { b: number|string }. >c3({ b: 1 }) : void >c3 : ({b}?: { b: string | number; }) => void >{ b: 1 } : { b: number; } >b : number +>1 : number c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] >c5([1, 2, [["string"]]]) : void >c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void >[1, 2, [["string"]]] : [number, number, [[string]]] +>1 : number +>2 : number >[["string"]] : [[string]] >["string"] : [string] +>"string" : string c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] >c5([1, 2, [["string"]], false, true]) : void >c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void >[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>1 : number +>2 : number >[["string"]] : [[string]] >["string"] : [string] +>"string" : string +>false : boolean +>true : boolean // A parameter can be marked optional by following its name or binding pattern with a question mark (?) @@ -327,7 +369,9 @@ function d5({x, y} = { x: 1, y: 2 }) { } >y : number >{ x: 1, y: 2 } : { x: number; y: number; } >x : number +>1 : number >y : number +>2 : number d5(); // Parameter is optional as its declaration included an initializer >d5() : void @@ -339,7 +383,7 @@ d5(); // Parameter is optional as its declaration included an initializer function e1({x: number}) { } // x has type any NOT number >e1 : ({x: number}: { x: any; }) => void ->x : unknown +>x : any >number : any function e2({x}: { x: number }) { } // x is type number @@ -354,14 +398,14 @@ function e3({x}: { x?: number }) { } // x is an optional with type number function e4({x: [number,string,any] }) { } // x has type [any, any, any] >e4 : ({x: [number,string,any] }: { x: [any, any, any]; }) => void ->x : unknown +>x : any >number : any >string : any >any : any function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] >e5 : ({x: [a, b, c]}: { x: [number, number, number]; }) => void ->x : unknown +>x : any >a : number >b : number >c : number @@ -369,7 +413,7 @@ function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; >e6 : ({x: [number, number, number]}: { x: [any, any, any]; }) => void ->x : unknown +>x : any >number : any >number : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 60f85604559..11af7b0d17c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -1,117 +1,194 @@ -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'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,4): error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. + Types of property '1' are incompatible. 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(7,29): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(8,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. + Types of property 'pop' are incompatible. + Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. + Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. + Type 'string' is not assignable to type 'number | string[][]'. + Type 'string' is not assignable to type 'string[][]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(23,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/destructuringParameterDeclaration2.ts(30,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(30,18): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(34,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/destructuringParameterDeclaration2.ts(35,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/destructuringParameterDeclaration2.ts(36,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/destructuringParameterDeclaration2.ts(37,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/destructuringParameterDeclaration2.ts(38,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/destructuringParameterDeclaration2.ts(39,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/destructuringParameterDeclaration2.ts(40,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/destructuringParameterDeclaration2.ts(46,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(47,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(55,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/destructuringParameterDeclaration2.ts(56,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -==== 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. +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (19 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. - // 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'. + // If the declaration includes a type annotation, the parameter is of that type + function a0([a, b, [[c]]]: [number, number, string[][]]) { } + a0([1, "string", [["world"]]); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. +!!! error TS2345: Types of property '1' are incompatible. !!! error TS2345: Type 'string' is not assignable to type 'number'. - - - class C { - constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier - ~~~ + ~ !!! error TS1005: ',' expected. + a0([1, 2, [["world"]], "string"]); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. +!!! error TS2345: Types of property 'pop' are incompatible. +!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. +!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type 'string' is not assignable to type 'string[][]'. + + + // 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. + + interface F1 { + b0(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. } - // 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"); + function b1(z = null, o = { x: 0, y: undefined }) { } + function b2([a, z, y] = [undefined, null, undefined]) { } + function b3([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } - 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'. + b1("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) + 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) { } // Error Duplicate identifier + ~ +!!! error TS2300: Duplicate identifier 'z'. + ~ +!!! error TS2300: Duplicate identifier 'z'. + function c5([a, b, [[c]]]) { } + function c6([a, b, [[c = 1]]]) { } + + 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; }; }'. + 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'. + c2({ z: false }); // 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'. + 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, 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. Initializers (including binding property or element initializers) are + // permitted only when the parameter list occurs in conjunction with a function body + + function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature + ~~~~~~~~~~ +!!! 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 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, binding pattern can't be optional in implementation signature + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + d4({x, y, c}) { } + e0([a, b, q]) { } + } + + // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, + // as such annotations would conflict with the already established meaning of colons in object literals. + // Type annotations must instead be written on the top- level parameter declaration + + function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js index 187966c3597..8033ff7eeae 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.js +++ b/tests/baselines/reference/destructuringParameterDeclaration2.js @@ -1,178 +1,149 @@ //// [destructuringParameterDeclaration2.ts] -// If the parameter is a rest parameter, the parameter type is any[] -// A type annotation for a rest parameter must denote an array type. +// 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. -// 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[]) { } +// If the declaration includes a type annotation, the parameter is of that type +function a0([a, b, [[c]]]: [number, number, string[][]]) { } +a0([1, "string", [["world"]]); // Error +a0([1, 2, [["world"]], "string"]); // Error -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)[] +// 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. -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) { } // Error, rest parameter can't have accessibilityModifier +interface F1 { + b0(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body } -// Rest parameter with generic -function foo(...a: T[]) { } -foo("hello", 1, 2); // Error -foo("hello", 1, 2); -foo("hello", "world"); +function b1(z = null, o = { x: 0, y: undefined }) { } +function b2([a, z, y] = [undefined, null, undefined]) { } +function b3([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } -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 +b1("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) +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) { } // Error Duplicate identifier +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c = 1]]]) { } + +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}? +c2({ z: false }); // Error, implied type is {z?: number} +c3({ b: true }); // Error, implied type is { b: number|string }. +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. Initializers (including binding property or element initializers) are +// permitted only when the parameter list occurs in conjunction with a function body + +function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature +function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C4 implements F2 { + d3([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature + d4({x, y, c}) { } + e0([a, b, q]) { } +} + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; //// [destructuringParameterDeclaration2.js] -// 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++) { - 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 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) { +// 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(_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); +a0([1, "string", [["world"]]]); // Error +a0([1, 2, [["world"]], "string"]); // Error +function b1(z, o) { + if (z === void 0) { z = null; } + if (o === void 0) { o = { x: 0, y: undefined }; } } -function a11(_a) { - var a = _a[0], b = _a[1], c = _a[2], x = _a.slice(3); +function b2(_a) { + var _b = _a === void 0 ? [undefined, null, undefined] : _a, a = _b[0], z = _b[1], y = _b[2]; } -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]; - } - } // Error, rest parameter can't have accessibilityModifier - return C; +function b3(_a) { + var _b = _a === void 0 ? [[undefined], undefined, [[undefined, undefined]]] : _a, a = _b[0][0], b = _b[1], _c = _b[2][0], c = _c[0], d = _c[1]; +} +b1("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) +function c0(_a) { + var _b = _a.z, x = _b.x, j = _b.y.j; +} +function c1(_a) { + var z = (_a === void 0 ? { z: 10 } : _a).z; +} +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]; +} // Error 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: 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}? +c2({ z: false }); // Error, implied type is {z?: number} +c3({ b: true }); // Error, implied type is { b: number|string }. +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. Initializers (including binding property or element initializers) are +// permitted only when the parameter list occurs in conjunction with a function body +function d1(_a) { + var a = _a[0], b = _a[1], c = _a[2]; +} // Error, binding pattern can't be optional in implementation signature +function d2(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} // Error, binding pattern can't be optional in implementation signature +var C4 = (function () { + function C4() { + } + C4.prototype.d3 = function (_a) { + var a = _a[0], b = _a[1], c = _a[2]; + }; // Error, binding pattern can't be optional in implementation signature + 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; })(); -// 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 +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration +function e0(_a) { + var _b = _a.x, number = _b[0], number = _b[1], number = _b[2]; +} // should be an error, duplicate identifier; diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES5.js similarity index 91% rename from tests/baselines/reference/destructuringParameterDeclaration2ES6.js rename to tests/baselines/reference/destructuringParameterDeclaration3ES5.js index 903384c7b42..5dea671ee1a 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.js @@ -1,4 +1,4 @@ -//// [destructuringParameterDeclaration2ES6.ts] +//// [destructuringParameterDeclaration3ES5.ts] // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -30,8 +30,7 @@ a9([1, 2, [["string"]], false, true]); // 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]); // Parameter type is number[] // Rest parameter with generic function foo(...a: T[]) { } @@ -47,7 +46,7 @@ foo1(1, 2, 3, E1.a, E.b); -//// [destructuringParameterDeclaration2ES6.js] +//// [destructuringParameterDeclaration3ES5.js] // 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 a1(...x) { } diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols b/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols new file mode 100644 index 00000000000..066be7f9e78 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols @@ -0,0 +1,145 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts === + +// 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 +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES5.ts, 0, 0)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type someArray = Array | number[]; +>someArray : Symbol(someArray, Decl(destructuringParameterDeclaration3ES5.ts, 7, 32)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type stringOrNumArray = Array; +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES5.ts, 8, 42)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + +function a1(...x: (number|string)[]) { } +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES5.ts, 9, 45)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5.ts, 11, 12)) + +function a2(...a) { } +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES5.ts, 11, 40)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 12, 12)) + +function a3(...a: Array) { } +>a3 : Symbol(a3, Decl(destructuringParameterDeclaration3ES5.ts, 12, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 13, 12)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +function a4(...a: arrayString) { } +>a4 : Symbol(a4, Decl(destructuringParameterDeclaration3ES5.ts, 13, 36)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 14, 12)) +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES5.ts, 0, 0)) + +function a5(...a: stringOrNumArray) { } +>a5 : Symbol(a5, Decl(destructuringParameterDeclaration3ES5.ts, 14, 34)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 15, 12)) +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES5.ts, 8, 42)) + +function a9([a, b, [[c]]]) { } +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES5.ts, 15, 39)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 16, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5.ts, 16, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5.ts, 16, 21)) + +function a10([a, b, [[c]], ...x]) { } +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 17, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5.ts, 17, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5.ts, 17, 22)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5.ts, 17, 26)) + +function a11([a, b, c, ...x]: number[]) { } +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES5.ts, 17, 37)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 18, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5.ts, 18, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5.ts, 18, 22)) + + +var array = [1, 2, 3]; +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5.ts, 21, 3)) + +var array2 = [true, false, "hello"]; +>array2 : Symbol(array2, Decl(destructuringParameterDeclaration3ES5.ts, 22, 3)) + +a2([...array]); +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES5.ts, 11, 40)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5.ts, 21, 3)) + +a1(...array); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES5.ts, 9, 45)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5.ts, 21, 3)) + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES5.ts, 15, 39)) + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) + +a10([1, 2]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) + +a11([1, 2]); // Parameter type is number[] +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES5.ts, 17, 37)) + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5.ts, 31, 12)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 34, 13)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 34, 16)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 34, 13)) + +foo("hello", 1, 2); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5.ts, 31, 12)) + +foo("hello", "world"); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5.ts, 31, 12)) + +enum E { a, b } +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5.ts, 38, 8)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5.ts, 38, 11)) + +const enum E1 { a, b } +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES5.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5.ts, 39, 15)) +>b : Symbol(E1.b, Decl(destructuringParameterDeclaration3ES5.ts, 39, 18)) + +function foo1(...a: T[]) { } +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5.ts, 39, 22)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 40, 14)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 40, 32)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 40, 14)) + +foo1(1, 2, 3, E.a); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5.ts, 39, 22)) +>E.a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5.ts, 38, 8)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5.ts, 38, 8)) + +foo1(1, 2, 3, E1.a, E.b); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5.ts, 39, 22)) +>E1.a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5.ts, 39, 15)) +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES5.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5.ts, 39, 15)) +>E.b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5.ts, 38, 11)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5.ts, 36, 22)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5.ts, 38, 11)) + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types similarity index 82% rename from tests/baselines/reference/destructuringParameterDeclaration2ES6.types rename to tests/baselines/reference/destructuringParameterDeclaration3ES5.types index 6215728fefb..64bede3e2de 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts === +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts === // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -70,10 +70,16 @@ function a11([a, b, c, ...x]: number[]) { } var array = [1, 2, 3]; >array : number[] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number var array2 = [true, false, "hello"]; >array2 : (string | boolean)[] >[true, false, "hello"] : (string | boolean)[] +>true : boolean +>false : boolean +>"hello" : string a2([...array]); >a2([...array]) : void @@ -92,30 +98,49 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] >a9([1, 2, [["string"]], false, true]) : void >a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void >[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>1 : number +>2 : number >[["string"]] : [[string]] >["string"] : [string] +>"string" : string +>false : boolean +>true : boolean a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void >[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>1 : number +>2 : number >[["string"]] : string[][] >["string"] : string[] +>"string" : string +>false : boolean +>true : boolean a10([1, 2, 3, false, true]); // Parameter type is any[] >a10([1, 2, 3, false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void >[1, 2, 3, false, true] : (number | boolean)[] +>1 : number +>2 : number +>3 : number +>false : boolean +>true : boolean a10([1, 2]); // Parameter type is any[] >a10([1, 2]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void >[1, 2] : number[] +>1 : number +>2 : number -a11([1, 2]); // Parameter type is number[] +a11([1, 2]); // Parameter type is number[] >a11([1, 2]) : void >a11 : ([a, b, c, ...x]: number[]) => void >[1, 2] : number[] +>1 : number +>2 : number // Rest parameter with generic function foo(...a: T[]) { } @@ -127,10 +152,15 @@ function foo(...a: T[]) { } foo("hello", 1, 2); >foo("hello", 1, 2) : void >foo : (...a: T[]) => void +>"hello" : string +>1 : number +>2 : number foo("hello", "world"); >foo("hello", "world") : void >foo : (...a: T[]) => void +>"hello" : string +>"world" : string enum E { a, b } >E : E @@ -152,6 +182,9 @@ function foo1(...a: T[]) { } foo1(1, 2, 3, E.a); >foo1(1, 2, 3, E.a) : void >foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number >E.a : E >E : typeof E >a : E @@ -159,6 +192,9 @@ foo1(1, 2, 3, E.a); foo1(1, 2, 3, E1.a, E.b); >foo1(1, 2, 3, E1.a, E.b) : void >foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number >E1.a : E1 >E1 : typeof E1 >a : E1 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js new file mode 100644 index 00000000000..5893168bf93 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js @@ -0,0 +1,80 @@ +//// [destructuringParameterDeclaration3ES6.ts] + +// 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 a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); + +a9([1, 2, [["string"]], false, true]); // 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[] + +// Rest parameter with generic +function foo(...a: T[]) { } +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); + + + + +//// [destructuringParameterDeclaration3ES6.js] +// 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 a1(...x) { } +function a2(...a) { } +function a3(...a) { } +function a4(...a) { } +function a5(...a) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]) { } +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); +a9([1, 2, [["string"]], false, true]); // 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[] +// Rest parameter with generic +function foo(...a) { } +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(...a) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, 0 /* a */, E.b); diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols b/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols new file mode 100644 index 00000000000..8e93a257033 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols @@ -0,0 +1,145 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts === + +// 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 +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES6.ts, 0, 0)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type someArray = Array | number[]; +>someArray : Symbol(someArray, Decl(destructuringParameterDeclaration3ES6.ts, 7, 32)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type stringOrNumArray = Array; +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES6.ts, 8, 42)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + +function a1(...x: (number|string)[]) { } +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES6.ts, 9, 45)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES6.ts, 11, 12)) + +function a2(...a) { } +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES6.ts, 11, 40)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 12, 12)) + +function a3(...a: Array) { } +>a3 : Symbol(a3, Decl(destructuringParameterDeclaration3ES6.ts, 12, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 13, 12)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +function a4(...a: arrayString) { } +>a4 : Symbol(a4, Decl(destructuringParameterDeclaration3ES6.ts, 13, 36)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 14, 12)) +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES6.ts, 0, 0)) + +function a5(...a: stringOrNumArray) { } +>a5 : Symbol(a5, Decl(destructuringParameterDeclaration3ES6.ts, 14, 34)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 15, 12)) +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES6.ts, 8, 42)) + +function a9([a, b, [[c]]]) { } +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES6.ts, 15, 39)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 16, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES6.ts, 16, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES6.ts, 16, 21)) + +function a10([a, b, [[c]], ...x]) { } +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 17, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES6.ts, 17, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES6.ts, 17, 22)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES6.ts, 17, 26)) + +function a11([a, b, c, ...x]: number[]) { } +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES6.ts, 17, 37)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 18, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES6.ts, 18, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES6.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES6.ts, 18, 22)) + + +var array = [1, 2, 3]; +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES6.ts, 21, 3)) + +var array2 = [true, false, "hello"]; +>array2 : Symbol(array2, Decl(destructuringParameterDeclaration3ES6.ts, 22, 3)) + +a2([...array]); +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES6.ts, 11, 40)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES6.ts, 21, 3)) + +a1(...array); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES6.ts, 9, 45)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES6.ts, 21, 3)) + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES6.ts, 15, 39)) + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) + +a10([1, 2]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) + +a11([1, 2]); // Parameter type is number[] +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES6.ts, 17, 37)) + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES6.ts, 31, 12)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 34, 13)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 34, 16)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 34, 13)) + +foo("hello", 1, 2); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES6.ts, 31, 12)) + +foo("hello", "world"); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES6.ts, 31, 12)) + +enum E { a, b } +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES6.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES6.ts, 38, 8)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES6.ts, 38, 11)) + +const enum E1 { a, b } +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES6.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES6.ts, 39, 15)) +>b : Symbol(E1.b, Decl(destructuringParameterDeclaration3ES6.ts, 39, 18)) + +function foo1(...a: T[]) { } +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES6.ts, 39, 22)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 40, 14)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 40, 32)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 40, 14)) + +foo1(1, 2, 3, E.a); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES6.ts, 39, 22)) +>E.a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES6.ts, 38, 8)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES6.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES6.ts, 38, 8)) + +foo1(1, 2, 3, E1.a, E.b); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES6.ts, 39, 22)) +>E1.a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES6.ts, 39, 15)) +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES6.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES6.ts, 39, 15)) +>E.b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES6.ts, 38, 11)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES6.ts, 36, 22)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES6.ts, 38, 11)) + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types new file mode 100644 index 00000000000..aea7b2ae15a --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -0,0 +1,206 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts === + +// 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 +>arrayString : String[] +>Array : T[] +>String : String + +type someArray = Array | number[]; +>someArray : number[] | String[] +>Array : T[] +>String : String + +type stringOrNumArray = Array; +>stringOrNumArray : (String | Number)[] +>Array : T[] +>String : String +>Number : Number + +function a1(...x: (number|string)[]) { } +>a1 : (...x: (string | number)[]) => void +>x : (string | number)[] + +function a2(...a) { } +>a2 : (...a: any[]) => void +>a : any[] + +function a3(...a: Array) { } +>a3 : (...a: String[]) => void +>a : String[] +>Array : T[] +>String : String + +function a4(...a: arrayString) { } +>a4 : (...a: String[]) => void +>a : String[] +>arrayString : String[] + +function a5(...a: stringOrNumArray) { } +>a5 : (...a: (String | Number)[]) => void +>a : (String | Number)[] +>stringOrNumArray : (String | Number)[] + +function a9([a, b, [[c]]]) { } +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>a : any +>b : any +>c : any + +function a10([a, b, [[c]], ...x]) { } +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a : any +>b : any +>c : any +>x : any[] + +function a11([a, b, c, ...x]: number[]) { } +>a11 : ([a, b, c, ...x]: number[]) => void +>a : number +>b : number +>c : number +>x : number[] + + +var array = [1, 2, 3]; +>array : number[] +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number + +var array2 = [true, false, "hello"]; +>array2 : (string | boolean)[] +>[true, false, "hello"] : (string | boolean)[] +>true : boolean +>false : boolean +>"hello" : string + +a2([...array]); +>a2([...array]) : void +>a2 : (...a: any[]) => void +>[...array] : number[] +>...array : number +>array : number[] + +a1(...array); +>a1(...array) : void +>a1 : (...x: (string | number)[]) => void +>...array : number +>array : number[] + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9([1, 2, [["string"]], false, true]) : void +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>1 : number +>2 : number +>[["string"]] : [[string]] +>["string"] : [string] +>"string" : string +>false : boolean +>true : boolean + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10([1, 2, [["string"]], false, true]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>1 : number +>2 : number +>[["string"]] : string[][] +>["string"] : string[] +>"string" : string +>false : boolean +>true : boolean + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10([1, 2, 3, false, true]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2, 3, false, true] : (number | boolean)[] +>1 : number +>2 : number +>3 : number +>false : boolean +>true : boolean + +a10([1, 2]); // Parameter type is any[] +>a10([1, 2]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2] : number[] +>1 : number +>2 : number + +a11([1, 2]); // Parameter type is number[] +>a11([1, 2]) : void +>a11 : ([a, b, c, ...x]: number[]) => void +>[1, 2] : number[] +>1 : number +>2 : number + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : (...a: T[]) => void +>T : T +>a : T[] +>T : T + +foo("hello", 1, 2); +>foo("hello", 1, 2) : void +>foo : (...a: T[]) => void +>"hello" : string +>1 : number +>2 : number + +foo("hello", "world"); +>foo("hello", "world") : void +>foo : (...a: T[]) => void +>"hello" : string +>"world" : string + +enum E { a, b } +>E : E +>a : E +>b : E + +const enum E1 { a, b } +>E1 : E1 +>a : E1 +>b : E1 + +function foo1(...a: T[]) { } +>foo1 : (...a: T[]) => void +>T : T +>Number : Number +>a : T[] +>T : T + +foo1(1, 2, 3, E.a); +>foo1(1, 2, 3, E.a) : void +>foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number +>E.a : E +>E : typeof E +>a : E + +foo1(1, 2, 3, E1.a, E.b); +>foo1(1, 2, 3, E1.a, E.b) : void +>foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number +>E1.a : E1 +>E1 : typeof E1 +>a : E1 +>E.b : E +>E : typeof E +>b : E + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index d5d0888e632..707fb005a80 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -1,78 +1,84 @@ -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(11,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,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/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,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/destructuringParameterDeclaration4.ts(23,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/destructuringParameterDeclaration4.ts(24,4): 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/destructuringParameterDeclaration4.ts(29,24): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,28): error TS2304: Cannot find name 'E'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (4 errors) ==== - // Parameter with generic - interface F { } - class Class implements F { - constructor() { } +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.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: someArray) { } // Error, rest parameter must be array type + ~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a3(...b?) { } // Error, can't be optional + function a4(...b = [1,2,3]) { } // Error, can't have initializer + function a5([a, b, [[c]]]) { } + function a6([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'. + a1(...array2); // Error parameter type is (number|string)[] + ~~~~~~ +!!! error TS2304: Cannot find name 'array2'. + a5([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'. + a5([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]'. + a6([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'. + + + var temp = [1, 2, 3]; + class C { + constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier + ~~~ +!!! error TS1005: ',' expected. } - class SubClass extends Class { - foo: boolean; - constructor() { super(); } - } - - class D implements F { - foo: boolean - constructor() { } - } - - class SubD extends D { - bar: number - constructor() { - super(); - } - } + // Rest parameter with generic + function foo1(...a: T[]) { } + foo1(1, 2, "string", E1.a, E.b); // Error + ~~ +!!! error TS2304: Cannot find name 'E1'. + ~ +!!! error TS2304: Cannot find name 'E'. - 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 + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.js b/tests/baselines/reference/destructuringParameterDeclaration4.js index 3eb0b3f8c19..adc5264e1ff 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.js +++ b/tests/baselines/reference/destructuringParameterDeclaration4.js @@ -1,113 +1,101 @@ //// [destructuringParameterDeclaration4.ts] -// Parameter with generic -interface F { } -class Class implements F { - constructor() { } +// 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: someArray) { } // Error, rest parameter must be array type +function a3(...b?) { } // Error, can't be optional +function a4(...b = [1,2,3]) { } // Error, can't have initializer +function a5([a, b, [[c]]]) { } +function a6([a, b, c, ...x]: number[]) { } + + +a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] +a1(...array2); // Error parameter type is (number|string)[] +a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a5([1, 2]); // Error, parameter type is [any, any, [[any]]] +a6([1, 2, "string"]); // Error, parameter type is number[] + + +var temp = [1, 2, 3]; +class C { + constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier } -class SubClass extends Class { - foo: boolean; - constructor() { super(); } -} - -class D implements F { - foo: boolean - constructor() { } -} - -class SubD extends D { - bar: number - constructor() { - super(); - } -} +// Rest parameter with generic +function foo1(...a: T[]) { } +foo1(1, 2, "string", E1.a, E.b); // Error -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 __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() { +// 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++) { + x[_i - 0] = arguments[_i]; } - return Class; +} // 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 a2() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} // Error, rest parameter must be array type +function a3() { + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} // Error, can't be optional +function a4() { + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} // Error, can't have initializer +function a5(_a) { + var a = _a[0], b = _a[1], c = _a[2][0][0]; +} +function a6(_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)[] +a1.apply(void 0, array2); // Error parameter type is (number|string)[] +a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a5([1, 2]); // Error, parameter type is [any, any, [[any]]] +a6([1, 2, "string"]); // Error, parameter type is number[] +var temp = [1, 2, 3]; +var C = (function () { + function C(public) { + var temp = []; + for (var _i = 1; _i < arguments.length; _i++) { + temp[_i - 1] = arguments[_i]; + } + } // Error, rest parameter can't have accessibilityModifier + return C; })(); -var SubClass = (function (_super) { - __extends(SubClass, _super); - function SubClass() { - _super.call(this); +// Rest parameter with generic +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 d1(_a) { - var x = _a.x; -} -function d2(_a) { - var x = _a.x; -} -function d3(_a) { - var y = _a.y; -} -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" }); +foo1(1, 2, "string", E1.a, E.b); // Error diff --git a/tests/baselines/reference/destructuringParameterDeclaration5.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration5.errors.txt new file mode 100644 index 00000000000..c60e2b75c37 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration5.errors.txt @@ -0,0 +1,79 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts(47,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/destructuringParameterDeclaration5.ts(48,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/destructuringParameterDeclaration5.ts(49,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/destructuringParameterDeclaration5.ts(50,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/destructuringParameterDeclaration5.ts (4 errors) ==== + // Parameter Declaration with generic + + interface F { } + class Class implements F { + constructor() { } + } + + 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() }); + ~~~~~~~~~~~~~~~~~~ +!!! 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/destructuringParameterDeclaration5.js b/tests/baselines/reference/destructuringParameterDeclaration5.js new file mode 100644 index 00000000000..2dea8224c65 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration5.js @@ -0,0 +1,115 @@ +//// [destructuringParameterDeclaration5.ts] +// Parameter Declaration with generic + +interface F { } +class Class implements F { + constructor() { } +} + +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" }); + +//// [destructuringParameterDeclaration5.js] +// Parameter Declaration with generic +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 Class; +})(); +var SubClass = (function (_super) { + __extends(SubClass, _super); + function SubClass() { + _super.call(this); + } + 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 d1(_a) { + var x = _a.x; +} +function d2(_a) { + var x = _a.x; +} +function d3(_a) { + var y = _a.y; +} +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/destructuringParameterDeclaration3.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration6.errors.txt similarity index 75% rename from tests/baselines/reference/destructuringParameterDeclaration3.errors.txt rename to tests/baselines/reference/destructuringParameterDeclaration6.errors.txt index 57777582731..e96f279b7e9 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration6.errors.txt @@ -1,16 +1,16 @@ -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/destructuringParameterDeclaration6.ts(9,14): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,19): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,21): error TS1109: Expression expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,24): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,26): error TS2304: Cannot find name 'public'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,32): error TS1005: ';' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,33): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(10,16): error TS1003: Identifier expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(10,21): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(12,13): error TS2370: A rest parameter must be of an array type. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts (10 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.js b/tests/baselines/reference/destructuringParameterDeclaration6.js similarity index 90% rename from tests/baselines/reference/destructuringParameterDeclaration3.js rename to tests/baselines/reference/destructuringParameterDeclaration6.js index a1abb86bd63..ff6662c4e86 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3.js +++ b/tests/baselines/reference/destructuringParameterDeclaration6.js @@ -1,4 +1,4 @@ -//// [destructuringParameterDeclaration3.ts] +//// [destructuringParameterDeclaration6.ts] // 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 @@ -21,7 +21,7 @@ b2({ while: 1 }); -//// [destructuringParameterDeclaration3.js] +//// [destructuringParameterDeclaration6.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";