Skip to content

Commit 647461f

Browse files
committed
fix(39440): show QF for abstract classes with methods which include 'this' parameter
1 parent c12d431 commit 647461f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/services/codefixes/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ namespace ts.codefix {
169169
if (!signatureDeclaration) {
170170
return undefined;
171171
}
172-
173172
let typeParameters = signatureDeclaration.typeParameters;
174173
let parameters = signatureDeclaration.parameters;
175174
let type = signatureDeclaration.type;
@@ -204,8 +203,9 @@ namespace ts.codefix {
204203
typeParameters = setTextRange(factory.createNodeArray(newTypeParameters, typeParameters.hasTrailingComma), typeParameters);
205204
}
206205
}
206+
const signatureParameters = signature.thisParameter ? [signature.thisParameter, ...signature.parameters] : signature.parameters;
207207
const newParameters = sameMap(parameters, (parameterDecl, i) => {
208-
const parameter = signature.parameters[i];
208+
const parameter = signatureParameters[i];
209209
const importableReference = tryGetAutoImportableReferenceFromImportTypeNode(parameterDecl.type, checker.getTypeAtLocation(parameter.valueDeclaration), scriptTarget);
210210
let type = parameterDecl.type;
211211
if (importableReference) {

tests/cases/fourslash/codeFixAmbientClassExtendAbstractMethod.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55
//// abstract f(a: number, b: string): this;
66
//// abstract f(a: string, b: number): Function;
77
//// abstract f(a: string): Function;
8+
////
9+
//// abstract f1(this: A): number;
10+
//// abstract f2(this: A, a: number, b: string): number;
11+
////
812
//// abstract foo(): number;
913
////}
1014
////
1115
////declare class C extends A {}
1216

1317
verify.codeFix({
14-
description: "Implement inherited abstract class",
18+
description: ts.Diagnostics.Implement_inherited_abstract_class.message,
1519
newFileContent:
1620
`abstract class A {
1721
abstract f(a: number, b: string): boolean;
1822
abstract f(a: number, b: string): this;
1923
abstract f(a: string, b: number): Function;
2024
abstract f(a: string): Function;
25+
26+
abstract f1(this: A): number;
27+
abstract f2(this: A, a: number, b: string): number;
28+
2129
abstract foo(): number;
2230
}
2331
@@ -26,6 +34,8 @@ declare class C extends A {
2634
f(a: number, b: string): this;
2735
f(a: string, b: number): Function;
2836
f(a: string): Function;
37+
f1(this: A): number;
38+
f2(this: A, a: number, b: string): number;
2939
foo(): number;
3040
}`
3141
});

0 commit comments

Comments
 (0)