diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index be2e6f9d8ab..257cf98b375 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37905,6 +37905,14 @@ namespace ts { } if (isBindingElement(node)) { + if (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 + error(node.name, Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation); + return; + } + if (isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < ScriptTarget.ES2018) { checkExternalEmitHelpers(node, ExternalEmitHelpers.Rest); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6078b781250..6d1df373a29 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3487,6 +3487,10 @@ "category": "Error", "code": 2841 }, + "Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.": { + "category": "Error", + "code": 2842 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error",