fixUnusedIdentifier: Don't remove setter parameter (#22488)
This commit is contained in:
parent
d3ede7b907
commit
83b438ffa6
|
@ -142,6 +142,11 @@ namespace ts.codefix {
|
|||
|
||||
case SyntaxKind.Parameter:
|
||||
const oldFunction = parent.parent;
|
||||
if (isSetAccessor(oldFunction)) {
|
||||
// Setter must have a parameter
|
||||
break;
|
||||
}
|
||||
|
||||
if (isArrowFunction(oldFunction) && oldFunction.parameters.length === 1) {
|
||||
// Lambdas with exactly one parameter are special because, after removal, there
|
||||
// must be an empty parameter list (i.e. `()`) and this won't necessarily be the
|
||||
|
|
19
tests/cases/fourslash/codeFixUnusedIdentifier_set.ts
Normal file
19
tests/cases/fourslash/codeFixUnusedIdentifier_set.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
|
||||
////class C {
|
||||
//// set x(value: number) {}
|
||||
////}
|
||||
|
||||
// No codefix to remove parameter, since setter must have a parameter
|
||||
verify.codeFixAvailable([{ description: "Prefix 'value' with an underscore" }]);
|
||||
|
||||
verify.codeFix({
|
||||
description: "Prefix 'value' with an underscore",
|
||||
newFileContent:
|
||||
`class C {
|
||||
set x(_value: number) {}
|
||||
}`,
|
||||
});
|
Loading…
Reference in a new issue