-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Forbid unused property renaming in destructuring binding in function types #41044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4aec8ef
a37d6d4
67732d3
1d114e6
4abcfa1
39e90ce
79ef4fd
69b8a58
4ddd9ae
e210484
2797958
cb326d2
17a29ff
c4c80db
1e3dc2e
32c340e
9c9fe5e
f0e5112
7aa2b6e
755c7c4
c7768cf
bdb42e1
6d4d147
bc92945
e2710b7
1e4c14b
4e519ff
07f162f
6c8a95b
bd0da30
600b614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1028,7 +1028,7 @@ namespace ts { | |
| const potentialReflectCollisions: Node[] = []; | ||
| const potentialAlwaysCheckedUnusedTypes: { | ||
| node: Node; | ||
| name: BindingName; | ||
| name: Identifier; | ||
| diagnostic: DiagnosticMessage; | ||
| }[] = []; | ||
| const awaitedTypeStack: number[] = []; | ||
|
|
@@ -37579,6 +37579,14 @@ namespace ts { | |
| }); | ||
| } | ||
|
||
|
|
||
| function checkPotentialAlwaysCheckedUnusedTypes() { | ||
| for (const { node, name, diagnostic } of potentialAlwaysCheckedUnusedTypes) { | ||
| if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { | ||
| error(name, diagnostic, declarationNameToString(name)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function bindingNameText(name: BindingName): string { | ||
| switch (name.kind) { | ||
| case SyntaxKind.Identifier: | ||
|
|
@@ -37933,7 +37941,7 @@ namespace ts { | |
| potentialAlwaysCheckedUnusedTypes.push({ | ||
| node, | ||
| name: node.name, | ||
| diagnostic: Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation | ||
| diagnostic: Diagnostics.Variable_0_is_not_used_Did_you_mean_to_write_a_type_annotation_for_whole_object | ||
| }); | ||
| return; | ||
| } | ||
|
|
@@ -41801,12 +41809,8 @@ namespace ts { | |
| } | ||
| }); | ||
| } | ||
| if (!node.isDeclarationFile && potentialAlwaysCheckedUnusedTypes.length) { | ||
| for (const { node, name, diagnostic } of potentialAlwaysCheckedUnusedTypes) { | ||
| if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { | ||
| error(name, diagnostic); | ||
| } | ||
| } | ||
| if (!node.isDeclarationFile) { | ||
| checkPotentialAlwaysCheckedUnusedTypes(); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3487,7 +3487,7 @@ | |
| "category": "Error", | ||
| "code": 2841 | ||
| }, | ||
| "Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.": { | ||
| "Variable '{0}' is not used. Did you mean to write a type annotation for whole object?": { | ||
|
||
| "category": "Error", | ||
| "code": 2842 | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,73 +1,73 @@ | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(3,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| 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(8,17): 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(18,17): 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(3,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(4,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
|
|
||
|
|
||
| ==== 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 | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type F3 = ({ a: string, b, c }: O) => any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type F4 = ({ a: string }: O) => any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type F5 = ({ a: string, b, c }: O) => any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type F6 = ({ a: string }) => typeof string; // OK | ||
| 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: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type F8 = ({ a, b: number }) => typeof number; // OK | ||
| type F9 = ([a, b, c]) => void; // Error | ||
|
|
||
| type G1 = (arg: number) => any; // OK | ||
| type G2 = ({ a: string }: O) => any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type G3 = ({ a: string, b, c }: O) => any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type G4 = ({ a: string }: O) => any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type G5 = ({ a: string, b, c }: O) => any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type G6 = ({ a: string }) => typeof string; // OK | ||
| 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: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| type G8 = ({ a, b: number }) => typeof number; // OK | ||
| type G9 = ([a, b, c]) => void; // Error | ||
|
|
||
| interface I { | ||
| method1(arg: number): any; // OK | ||
| method2({ a: string }): any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
|
|
||
| (arg: number): any; // OK | ||
| ({ a: string }): any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
|
|
||
| new (arg: number): any; // OK | ||
| new ({ a: string }): any; // Error | ||
| ~~~~~~ | ||
| !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. | ||
| !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? | ||
| } |


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
nameanddiagnosticare always predictable / derivable fromnode, so this can just beNode[]like the others. (I don’t think there’s a need to try to make it general-purpose for future use.) I also don’t like the name but it’s extremely hard to come up with anything better...potentialUnusedRenamedBindingElementsInTypes? 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for feedback, fixed 🙂