mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
get correct result
This commit is contained in:
1 parent
39e90ce1e1
commit
79ef4fd0b0
3 files changed
+27
-115
No files matched your search
+26
-3
@@ -1026,6 +1026,11 @@ namespace ts {
|
||||
const potentialNewTargetCollisions: Node[] = [];
|
||||
const potentialWeakMapSetCollisions: Node[] = [];
|
||||
const potentialReflectCollisions: Node[] = [];
|
||||
const potentialAlwaysCheckedUnusedTypes: {
|
||||
node: Node;
|
||||
name: BindingName;
|
||||
diagnostic: DiagnosticMessage;
|
||||
}[] = [];
|
||||
const awaitedTypeStack: number[] = [];
|
||||
|
||||
const diagnostics = createDiagnosticCollection();
|
||||
@@ -37915,11 +37920,21 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (isBindingElement(node)) {
|
||||
if (node.propertyName && isIdentifier(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
|
||||
error(node.name, Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation);
|
||||
// variable renaming in function type notation is confusing,
|
||||
// so we forbid it even if noUnusedLocals is not enabled
|
||||
potentialAlwaysCheckedUnusedTypes.push({
|
||||
node,
|
||||
name: node.name,
|
||||
diagnostic: Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41766,6 +41781,7 @@ namespace ts {
|
||||
clear(potentialNewTargetCollisions);
|
||||
clear(potentialWeakMapSetCollisions);
|
||||
clear(potentialReflectCollisions);
|
||||
clear(potentialAlwaysCheckedUnusedTypes);
|
||||
|
||||
forEach(node.statements, checkSourceElement);
|
||||
checkSourceElement(node.endOfFileToken);
|
||||
@@ -41785,6 +41801,13 @@ namespace ts {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!node.isDeclarationFile && potentialAlwaysCheckedUnusedTypes.length) {
|
||||
for (const { node, name, diagnostic } of potentialAlwaysCheckedUnusedTypes) {
|
||||
if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) {
|
||||
error(name, diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Error &&
|
||||
|
||||
@@ -2,24 +2,18 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(3,17): error
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(4,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(19,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,16): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,9): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
|
||||
|
||||
==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (19 errors) ====
|
||||
==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (13 errors) ====
|
||||
type O = { a: string; b: number; c: number; };
|
||||
type F1 = (arg: number) => any; // OK
|
||||
type F2 = ({ a: string }: O) => any; // Error
|
||||
@@ -35,16 +29,10 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F6 = ({ a: string }) => typeof string; // OK
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F7 = ({ a: string, b: number }) => typeof number; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F8 = ({ a, b: number }) => typeof number; // OK
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F9 = ([a, b, c]) => void; // Error
|
||||
|
||||
type G1 = (arg: number) => any; // OK
|
||||
@@ -61,16 +49,10 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G6 = ({ a: string }) => typeof string; // OK
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G7 = ({ a: string, b: number }) => typeof number; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G8 = ({ a, b: number }) => typeof number; // OK
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G9 = ([a, b, c]) => void; // Error
|
||||
|
||||
interface I {
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
tests/cases/compiler/a.d.ts(3,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(4,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(5,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(6,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(7,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(8,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(8,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(9,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(13,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(14,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(15,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(16,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(17,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(18,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(18,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(19,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(24,16): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(27,9): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
tests/cases/compiler/a.d.ts(30,13): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.d.ts (19 errors) ====
|
||||
type O = { a: string; b: number; c: number; };
|
||||
type F1 = (arg: number) => any;
|
||||
type F2 = ({ a: string }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F3 = ({ a: string, b, c }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F4 = ({ a: string }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F5 = ({ a: string, b, c }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F6 = ({ a: string }) => typeof string;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F7 = ({ a: string, b: number }) => typeof number;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F8 = ({ a, b: number }) => typeof number;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type F9 = ([a, b, c]) => void;
|
||||
|
||||
type G1 = (arg: number) => any;
|
||||
type G2 = ({ a: string }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G3 = ({ a: string, b, c }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G4 = ({ a: string }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G5 = ({ a: string, b, c }: O) => any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G6 = ({ a: string }) => typeof string;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G7 = ({ a: string, b: number }) => typeof number;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G8 = ({ a, b: number }) => typeof number;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
type G9 = ([a, b, c]) => void;
|
||||
|
||||
interface I {
|
||||
method1(arg: number): any;
|
||||
method2({ a: string }): any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
|
||||
(arg: number): any;
|
||||
({ a: string }): any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
|
||||
new (arg: number): any;
|
||||
new ({ a: string }): any;
|
||||
~~~~~~
|
||||
!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user