From 469745b1819c32851f61c04bb5032e3e035d1e4d Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Sun, 11 Dec 2016 21:50:46 -0800 Subject: [PATCH] Synthetic signature uses existing parameter names --- .../fixClassDoesntImplementInheritedAbstractMember.ts | 2 +- src/services/codefixes/helpers.ts | 5 ++++- tests/cases/fourslash/codeFixClassExtendsAbstractMethod.ts | 2 +- ...plementedInterfaceComputedPropertyNameWellKnownSymbols.ts | 2 +- .../codeFixUnImplementedInterfaceMultipleSignatures.ts | 2 +- .../codeFixUnImplementedInterfaceMultipleSignaturesRest1.ts | 2 +- .../codeFixUnImplementedInterfaceMultipleSignaturesRest2.ts | 2 +- 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts b/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts index cfb771e2324..86463b60f35 100644 --- a/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts +++ b/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts @@ -20,7 +20,7 @@ namespace ts.codefix { const insertion = getMissingMembersInsertion(classDecl, abstractAndNonPrivateExtendsSymbols, checker, context.newLineCharacter); - if (insertion) { + if (insertion.length) { return [{ description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class), changes: [{ diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index d2122d95382..1bc4278144f 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -93,6 +93,7 @@ namespace ts.codefix { newSignatureDeclaration.name = signatures[0].getDeclaration().name; let maxNonRestArgs = -1; + let maxArgsIndex = 0; let minArgumentCount = signatures[0].minArgumentCount; let hasRestParameter = false; for (let i = 0; i < signatures.length; i++) { @@ -102,8 +103,10 @@ namespace ts.codefix { const nonRestLength = sig.parameters.length - (sig.hasRestParameter ? 1 : 0); if (nonRestLength > maxNonRestArgs) { maxNonRestArgs = nonRestLength; + maxArgsIndex = i; } } + const maxArgsParameterSymbolNames = signatures[maxArgsIndex].getParameters().map(symbol => symbol.getName()); const anyTypeNode: TypeNode = createNode(SyntaxKind.AnyKeyword) as TypeNode; const optionalToken = createToken(SyntaxKind.QuestionToken); @@ -130,7 +133,7 @@ namespace ts.codefix { function createParameterDeclaration(index: number, minArgCount: number, typeNode: TypeNode, enclosingSignatureDeclaration: SignatureDeclaration): ParameterDeclaration { const newParameter = createNode(SyntaxKind.Parameter) as ParameterDeclaration; - newParameter.symbol = checker.createSymbol(SymbolFlags.FunctionScopedVariable, "arg" + index); + newParameter.symbol = checker.createSymbol(SymbolFlags.FunctionScopedVariable, maxArgsParameterSymbolNames[index] || "rest"); newParameter.symbol.valueDeclaration = newParameter; newParameter.symbol.declarations = [newParameter]; newParameter.type = typeNode; diff --git a/tests/cases/fourslash/codeFixClassExtendsAbstractMethod.ts b/tests/cases/fourslash/codeFixClassExtendsAbstractMethod.ts index 587b5d9b2b7..a657dfeb718 100644 --- a/tests/cases/fourslash/codeFixClassExtendsAbstractMethod.ts +++ b/tests/cases/fourslash/codeFixClassExtendsAbstractMethod.ts @@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(` f(a: number, b: string): boolean; f(a: string, b: number): Function; f(a: string): Function; - f(arg0: any, arg1?: any) { + f(a: any, b?: any) { throw new Error('Method not implemented.'); } `); diff --git a/tests/cases/fourslash/codeFixUnImplementedInterfaceComputedPropertyNameWellKnownSymbols.ts b/tests/cases/fourslash/codeFixUnImplementedInterfaceComputedPropertyNameWellKnownSymbols.ts index 8a6e7e8f2d8..7c1156acd78 100644 --- a/tests/cases/fourslash/codeFixUnImplementedInterfaceComputedPropertyNameWellKnownSymbols.ts +++ b/tests/cases/fourslash/codeFixUnImplementedInterfaceComputedPropertyNameWellKnownSymbols.ts @@ -44,7 +44,7 @@ verify.rangeAfterCodeFix(` [Symbol.toPrimitive](hint: "number"): number; [Symbol.toPrimitive](hint: "default"): number; [Symbol.toPrimitive](hint: "string"): string; - [Symbol.toPrimitive](arg0: any) { + [Symbol.toPrimitive](hint: any) { throw new Error('Method not implemented.'); } [Symbol.toStringTag]: string; diff --git a/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignatures.ts b/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignatures.ts index ce777567e1e..bda58b3767d 100644 --- a/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignatures.ts +++ b/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignatures.ts @@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(` method(a: number, b: string): boolean; method(a: string, b: number): Function; method(a: string): Function; - method(arg0: any, arg1?: any) { + method(a: any, b?: any) { throw new Error('Method not implemented.'); } `); diff --git a/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest1.ts b/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest1.ts index a473b9dccbe..6e0a272a42a 100644 --- a/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest1.ts +++ b/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest1.ts @@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(` method(a: number, ...b: string[]): boolean; method(a: string, ...b: number[]): Function; method(a: string): Function; - method(arg0: any, ...arg1?: any[]) { + method(a: any, ...b?: any[]) { throw new Error('Method not implemented.'); } `); diff --git a/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest2.ts b/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest2.ts index 7cacbda171b..7ba7ae2c98c 100644 --- a/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest2.ts +++ b/tests/cases/fourslash/codeFixUnImplementedInterfaceMultipleSignaturesRest2.ts @@ -12,7 +12,7 @@ verify.rangeAfterCodeFix(` method(a: number, ...b: string[]): boolean; method(a: string, b: number): Function; method(a: string): Function; - method(arg0: any, arg1?: any, ...arg2?: any[]) { + method(a: any, b?: any, ...rest?: any[]) { throw new Error('Method not implemented.'); } `);