mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 03:09:39 -06:00
fix(57497): "Remove unused declaration" does not work on overloaded function declarations (#57517)
This commit is contained in:
parent
c0ac582284
commit
93451e8dd9
@ -27,6 +27,7 @@ import {
|
||||
isComputedPropertyName,
|
||||
isDeclarationWithTypeParameterChildren,
|
||||
isExpressionStatement,
|
||||
isFunctionDeclaration,
|
||||
isIdentifier,
|
||||
isImportClause,
|
||||
isImportDeclaration,
|
||||
@ -129,6 +130,10 @@ registerCodeFix({
|
||||
];
|
||||
}
|
||||
|
||||
if (isIdentifier(token) && isFunctionDeclaration(token.parent)) {
|
||||
return [createDeleteFix(textChanges.ChangeTracker.with(context, t => deleteFunctionLikeDeclaration(t, sourceFile, token.parent as FunctionLikeDeclaration)), [Diagnostics.Remove_unused_declaration_for_Colon_0, token.getText(sourceFile)])];
|
||||
}
|
||||
|
||||
const result: CodeFixAction[] = [];
|
||||
if (token.kind === SyntaxKind.InferKeyword) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => changeInferToUnknown(t, sourceFile, token));
|
||||
@ -431,3 +436,12 @@ function mayDeleteExpression(node: Node) {
|
||||
return ((isBinaryExpression(node.parent) && node.parent.left === node) ||
|
||||
((isPostfixUnaryExpression(node.parent) || isPrefixUnaryExpression(node.parent)) && node.parent.operand === node)) && isExpressionStatement(node.parent.parent);
|
||||
}
|
||||
|
||||
function deleteFunctionLikeDeclaration(changes: textChanges.ChangeTracker, sourceFile: SourceFile, node: FunctionLikeDeclaration) {
|
||||
const declarations = node.symbol.declarations;
|
||||
if (declarations) {
|
||||
for (const declaration of declarations) {
|
||||
changes.delete(sourceFile, declaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
19
tests/cases/fourslash/codeFixUnusedIdentifier_overloads.ts
Normal file
19
tests/cases/fourslash/codeFixUnusedIdentifier_overloads.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
|
||||
////function foo(): number;
|
||||
////function foo(x: number, y: number): number;
|
||||
////function foo(x?: number, y?: number): number {
|
||||
//// return 1234;
|
||||
////}
|
||||
////
|
||||
////export {}
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: "Remove unused declaration for: 'foo'",
|
||||
newFileContent:
|
||||
`
|
||||
export {}`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user