Skip to content

Commit 469745b

Browse files
author
Arthur Ozga
committed
Synthetic signature uses existing parameter names
1 parent d724517 commit 469745b

7 files changed

+10
-7
lines changed

src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ts.codefix {
2020

2121
const insertion = getMissingMembersInsertion(classDecl, abstractAndNonPrivateExtendsSymbols, checker, context.newLineCharacter);
2222

23-
if (insertion) {
23+
if (insertion.length) {
2424
return [{
2525
description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
2626
changes: [{

src/services/codefixes/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ namespace ts.codefix {
9393
newSignatureDeclaration.name = signatures[0].getDeclaration().name;
9494

9595
let maxNonRestArgs = -1;
96+
let maxArgsIndex = 0;
9697
let minArgumentCount = signatures[0].minArgumentCount;
9798
let hasRestParameter = false;
9899
for (let i = 0; i < signatures.length; i++) {
@@ -102,8 +103,10 @@ namespace ts.codefix {
102103
const nonRestLength = sig.parameters.length - (sig.hasRestParameter ? 1 : 0);
103104
if (nonRestLength > maxNonRestArgs) {
104105
maxNonRestArgs = nonRestLength;
106+
maxArgsIndex = i;
105107
}
106108
}
109+
const maxArgsParameterSymbolNames = signatures[maxArgsIndex].getParameters().map(symbol => symbol.getName());
107110

108111
const anyTypeNode: TypeNode = createNode(SyntaxKind.AnyKeyword) as TypeNode;
109112
const optionalToken = createToken(SyntaxKind.QuestionToken);
@@ -130,7 +133,7 @@ namespace ts.codefix {
130133

131134
function createParameterDeclaration(index: number, minArgCount: number, typeNode: TypeNode, enclosingSignatureDeclaration: SignatureDeclaration): ParameterDeclaration {
132135
const newParameter = createNode(SyntaxKind.Parameter) as ParameterDeclaration;
133-
newParameter.symbol = checker.createSymbol(SymbolFlags.FunctionScopedVariable, "arg" + index);
136+
newParameter.symbol = checker.createSymbol(SymbolFlags.FunctionScopedVariable, maxArgsParameterSymbolNames[index] || "rest");
134137
newParameter.symbol.valueDeclaration = newParameter;
135138
newParameter.symbol.declarations = [newParameter];
136139
newParameter.type = typeNode;

tests/cases/fourslash/codeFixClassExtendsAbstractMethod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(`
1212
f(a: number, b: string): boolean;
1313
f(a: string, b: number): Function;
1414
f(a: string): Function;
15-
f(arg0: any, arg1?: any) {
15+
f(a: any, b?: any) {
1616
throw new Error('Method not implemented.');
1717
}
1818
`);

tests/cases/fourslash/codeFixUnImplementedInterfaceComputedPropertyNameWellKnownSymbols.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ verify.rangeAfterCodeFix(`
4444
[Symbol.toPrimitive](hint: "number"): number;
4545
[Symbol.toPrimitive](hint: "default"): number;
4646
[Symbol.toPrimitive](hint: "string"): string;
47-
[Symbol.toPrimitive](arg0: any) {
47+
[Symbol.toPrimitive](hint: any) {
4848
throw new Error('Method not implemented.');
4949
}
5050
[Symbol.toStringTag]: string;

tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignatures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(`
1212
method(a: number, b: string): boolean;
1313
method(a: string, b: number): Function;
1414
method(a: string): Function;
15-
method(arg0: any, arg1?: any) {
15+
method(a: any, b?: any) {
1616
throw new Error('Method not implemented.');
1717
}
1818
`);

tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(`
1212
method(a: number, ...b: string[]): boolean;
1313
method(a: string, ...b: number[]): Function;
1414
method(a: string): Function;
15-
method(arg0: any, ...arg1?: any[]) {
15+
method(a: any, ...b?: any[]) {
1616
throw new Error('Method not implemented.');
1717
}
1818
`);

tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(`
1212
method(a: number, ...b: string[]): boolean;
1313
method(a: string, b: number): Function;
1414
method(a: string): Function;
15-
method(arg0: any, arg1?: any, ...arg2?: any[]) {
15+
method(a: any, b?: any, ...rest?: any[]) {
1616
throw new Error('Method not implemented.');
1717
}
1818
`);

0 commit comments

Comments
 (0)