Skip to content

Commit e6e7197

Browse files
committed
Correct codefix by removing private modifier
In case of private attribute and private constructor parameter with assignment in the constructor body, the parameter is flagged as unused. This is caused by the private modifier which is shadowed by the explicity assignment in the body. This commit updates the codefix to just remove the private modifier in this cases. Closes #24931
1 parent 6b641de commit e6e7197

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/services/codefixes/fixUnusedIdentifier.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,14 @@ namespace ts.codefix {
200200

201201
function tryDeleteParameter(changes: textChanges.ChangeTracker, sourceFile: SourceFile, p: ParameterDeclaration, checker: TypeChecker, sourceFiles: ReadonlyArray<SourceFile>, isFixAll: boolean): void {
202202
if (mayDeleteParameter(p, checker, isFixAll)) {
203-
changes.delete(sourceFile, p);
204-
deleteUnusedArguments(changes, sourceFile, p, sourceFiles, checker);
203+
const privateModifier = ts.findModifier(p, ts.SyntaxKind.PrivateKeyword);
204+
if (privateModifier) {
205+
changes.deleteModifier(sourceFile, p.modifiers![0]);
206+
}
207+
else {
208+
changes.delete(sourceFile, p);
209+
deleteUnusedArguments(changes, sourceFile, p, sourceFiles, checker);
210+
}
205211
}
206212
}
207213

0 commit comments

Comments
 (0)