fixUnusedIdentifier: Don't remove setter parameter (#22488)

This commit is contained in:
Andy
2018-03-12 16:07:20 -07:00
committed by GitHub
parent d3ede7b907
commit 83b438ffa6
2 changed files with 24 additions and 0 deletions

View File

@@ -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

View 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) {}
}`,
});