diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index 257cf98b375..6cd04997179 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -5964,19 +5964,29 @@ namespace ts {
return parameterNode;
function cloneBindingName(node: BindingName): BindingName {
- return elideInitializerAndSetEmitFlags(node) as BindingName;
- function elideInitializerAndSetEmitFlags(node: Node): Node {
+ return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName;
+ function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node {
if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) {
trackComputedName(node.expression, context.enclosingDeclaration, context);
}
- let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
+ let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!;
if (isBindingElement(visited)) {
- visited = factory.updateBindingElement(
- visited,
- visited.dotDotDotToken,
- visited.propertyName,
- visited.name,
- /*initializer*/ undefined);
+ if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name)) {
+ visited = factory.updateBindingElement(
+ visited,
+ visited.dotDotDotToken,
+ /* propertyName*/ undefined,
+ visited.propertyName,
+ /*initializer*/ undefined);
+ }
+ else {
+ visited = factory.updateBindingElement(
+ visited,
+ visited.dotDotDotToken,
+ visited.propertyName,
+ visited.name,
+ /*initializer*/ undefined);
+ }
}
if (!nodeIsSynthesized(visited)) {
visited = factory.cloneNode(visited);
@@ -37905,7 +37915,7 @@ namespace ts {
}
if (isBindingElement(node)) {
- if (node.propertyName && isIdentifier(node.name) && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) {
+ if (node.propertyName && isIdentifier(node.propertyName) && isIdentifier(node.name) && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) {
// type F = ({a: string}) => void;
// ^^^^^^
// variable renaming in function type notation is confusing, so forbid it
diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts
index 76db95b2603..3453eae95b2 100644
--- a/src/compiler/transformers/declarations.ts
+++ b/src/compiler/transformers/declarations.ts
@@ -454,7 +454,7 @@ namespace ts {
return ret;
}
- function filterBindingPatternInitializers(name: BindingName) {
+ function filterBindingPatternInitializersAndRenamings(name: BindingName) {
if (name.kind === SyntaxKind.Identifier) {
return name;
}
@@ -472,7 +472,23 @@ namespace ts {
if (elem.kind === SyntaxKind.OmittedExpression) {
return elem;
}
- return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializers(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
+ if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name)) {
+ // Property renaming is forbidden in types, so remove renaming
+ return factory.updateBindingElement(
+ elem,
+ elem.dotDotDotToken,
+ /* propertyName */ undefined,
+ elem.propertyName,
+ shouldPrintWithInitializer(elem) ? elem.initializer : undefined
+ );
+ }
+ return factory.updateBindingElement(
+ elem,
+ elem.dotDotDotToken,
+ elem.propertyName,
+ filterBindingPatternInitializersAndRenamings(elem.name),
+ shouldPrintWithInitializer(elem) ? elem.initializer : undefined
+ );
}
}
@@ -487,7 +503,7 @@ namespace ts {
/*decorators*/ undefined,
maskModifiers(p, modifierMask),
p.dotDotDotToken,
- filterBindingPatternInitializers(p.name),
+ filterBindingPatternInitializersAndRenamings(p.name),
resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined,
ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
ensureNoInitializer(p)
diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.js b/tests/baselines/reference/declarationEmitBindingPatterns.js
index 5581c06ebe6..31114071a29 100644
--- a/tests/baselines/reference/declarationEmitBindingPatterns.js
+++ b/tests/baselines/reference/declarationEmitBindingPatterns.js
@@ -18,7 +18,7 @@ function f(_a, _b, _c) {
//// [declarationEmitBindingPatterns.d.ts]
-declare const k: ({ x: z }: {
+declare const k: ({ x }: {
x?: string;
}) => void;
declare var a: any;
diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.types b/tests/baselines/reference/declarationEmitBindingPatterns.types
index d49893dad94..151991e3039 100644
--- a/tests/baselines/reference/declarationEmitBindingPatterns.types
+++ b/tests/baselines/reference/declarationEmitBindingPatterns.types
@@ -1,7 +1,7 @@
=== tests/cases/compiler/declarationEmitBindingPatterns.ts ===
const k = ({x: z = 'y'}) => { }
->k : ({ x: z }: { x?: string; }) => void
->({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void
+>k : ({ x }: { x?: string; }) => void
+>({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void
>x : any
>z : string
>'y' : "y"
diff --git a/tests/baselines/reference/destructuringInFunctionType.errors.txt b/tests/baselines/reference/destructuringInFunctionType.errors.txt
new file mode 100644
index 00000000000..da7a2fc32bb
--- /dev/null
+++ b/tests/baselines/reference/destructuringInFunctionType.errors.txt
@@ -0,0 +1,30 @@
+tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+
+
+==== tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts (2 errors) ====
+ interface a { a }
+ interface b { b }
+ interface c { c }
+
+ type T1 = ([a, b, c]);
+ type F1 = ([a, b, c]) => void;
+
+ type T2 = ({ a });
+ type F2 = ({ a }) => void;
+
+ type T3 = ([{ a: b }, { b: a }]);
+ type F3 = ([{ a: b }, { b: a }]) => void;
+ ~
+!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+ ~
+!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+
+ type T4 = ([{ a: [b, c] }]);
+ type F4 = ([{ a: [b, c] }]) => void;
+
+ type C1 = new ([{ a: [b, c] }]) => void;
+
+ var v1 = ([a, b, c]) => "hello";
+ var v2: ([a, b, c]) => string;
+
\ No newline at end of file
diff --git a/tests/baselines/reference/destructuringInFunctionType.js b/tests/baselines/reference/destructuringInFunctionType.js
index 1844e8e5a8d..1a38ef067ac 100644
--- a/tests/baselines/reference/destructuringInFunctionType.js
+++ b/tests/baselines/reference/destructuringInFunctionType.js
@@ -52,7 +52,7 @@ declare type T3 = ([{
}, {
b: a;
}]);
-declare type F3 = ([{ a: b }, { b: a }]: [{
+declare type F3 = ([{ a }, { b }]: [{
a: any;
}, {
b: any;
diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt
new file mode 100644
index 00000000000..9ae33a27580
--- /dev/null
+++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt
@@ -0,0 +1,23 @@
+tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+
+
+==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (1 errors) ====
+ declare function f({ a: number }): void
+ ~~~~~~
+!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+ interface I {
+ readonly n: number;
+ }
+ declare let i: I;
+ f({ a: 1, ...i });
+
+ interface R {
+ opt?: number
+ }
+ interface L {
+ opt: string
+ }
+ declare let l: L;
+ declare let r: R;
+ f({ a: 1, ...l, ...r });
+
\ No newline at end of file
diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt
new file mode 100644
index 00000000000..69e5d888a1b
--- /dev/null
+++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt
@@ -0,0 +1,14 @@
+tests/cases/compiler/paramterDestrcuturingDeclaration.ts(2,10): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+
+
+==== tests/cases/compiler/paramterDestrcuturingDeclaration.ts (2 errors) ====
+ interface C {
+ ({p: name}): any;
+ ~~~~
+!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+ new ({p: boolean}): any;
+ ~~~~~~~
+!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+ }
+
\ No newline at end of file
diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.js b/tests/baselines/reference/paramterDestrcuturingDeclaration.js
index 3ce2527f572..e0cf710a528 100644
--- a/tests/baselines/reference/paramterDestrcuturingDeclaration.js
+++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.js
@@ -10,10 +10,10 @@ interface C {
//// [paramterDestrcuturingDeclaration.d.ts]
interface C {
- ({ p: name }: {
+ ({ p }: {
p: any;
}): any;
- new ({ p: boolean }: {
+ new ({ p }: {
p: any;
}): any;
}
diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt
new file mode 100644
index 00000000000..69c6d7d79e3
--- /dev/null
+++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt
@@ -0,0 +1,48 @@
+tests/cases/conformance/jsx/file.tsx(17,39): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+
+
+==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
+ import React = require('react')
+
+ declare function OneThing(k: {yxx: string}): JSX.Element;
+ declare function OneThing(k: {yxx1: string, children: string}): JSX.Element;
+ declare function OneThing(l: {yy: number, yy1: string}): JSX.Element;
+ declare function OneThing(l: {yy: number, yy1: string, yy2: boolean}): JSX.Element;
+ declare function OneThing(l1: {data: string, "data-prop": boolean}): JSX.Element;
+
+ // OK
+ const c1 =
+ const c2 =
+ const c3 =
+ const c4 =
+ const c5 = Hello
+
+
+ declare function TestingOneThing({y1: string}): JSX.Element;
+ ~~~~~~
+!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
+ declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element;
+ declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element;
+ declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element;
+
+ // OK
+ const d1 = ;
+ const d2 = ;
+ const d3 = ;
+ const d4 = ;
+ const d5 = ;
+
+
+ declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element;
+ declare function TestingOptional(a: {y1: boolean, y2?: number, y3: boolean}): JSX.Element;
+
+ // OK
+ const e1 =
+ const e3 =
+ const e4 =
+ const e5 =
+ const e6 =
+ const e2 =
+
+
+
\ No newline at end of file