Skip to content

Commit 83b438f

Browse files
author
Andy
authored
fixUnusedIdentifier: Don't remove setter parameter (microsoft#22488)
1 parent d3ede7b commit 83b438f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/services/codefixes/fixUnusedIdentifier.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ namespace ts.codefix {
142142

143143
case SyntaxKind.Parameter:
144144
const oldFunction = parent.parent;
145+
if (isSetAccessor(oldFunction)) {
146+
// Setter must have a parameter
147+
break;
148+
}
149+
145150
if (isArrowFunction(oldFunction) && oldFunction.parameters.length === 1) {
146151
// Lambdas with exactly one parameter are special because, after removal, there
147152
// must be an empty parameter list (i.e. `()`) and this won't necessarily be the
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noUnusedLocals: true
4+
// @noUnusedParameters: true
5+
6+
////class C {
7+
//// set x(value: number) {}
8+
////}
9+
10+
// No codefix to remove parameter, since setter must have a parameter
11+
verify.codeFixAvailable([{ description: "Prefix 'value' with an underscore" }]);
12+
13+
verify.codeFix({
14+
description: "Prefix 'value' with an underscore",
15+
newFileContent:
16+
`class C {
17+
set x(_value: number) {}
18+
}`,
19+
});

0 commit comments

Comments
 (0)