Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aeeeee5

Browse files
Avoid generating implementation signatures in ambient contexts.
1 parent 0b264db commit aeeeee5

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

src/services/codefixes/helpers.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ namespace ts.codefix {
9393
// (eg: an abstract method or interface declaration), there is a 1-1
9494
// correspondence of declarations and signatures.
9595
const signatures = checker.getSignaturesOfType(type, SignatureKind.Call);
96+
const needsImplementation = !isInAmbientContext(enclosingDeclaration);
9697
if (!some(signatures)) {
9798
return undefined;
9899
}
99100

100101
if (declarations.length === 1) {
101102
Debug.assert(signatures.length === 1);
102103
const signature = signatures[0];
103-
return signatureToMethodDeclaration(signature, enclosingDeclaration, createStubbedMethodBody());
104+
const body = needsImplementation ? createStubbedMethodBody() : undefined;
105+
return signatureToMethodDeclaration(signature, enclosingDeclaration, body);
104106
}
105107

106108
const signatureDeclarations: MethodDeclaration[] = [];
@@ -119,7 +121,7 @@ namespace ts.codefix {
119121
signatureDeclarations.push(methodDeclaration);
120122
}
121123
}
122-
else {
124+
else if (needsImplementation) {
123125
Debug.assert(declarations.length === signatures.length);
124126
const methodImplementingSignatures = createMethodImplementingSignatures(signatures, name, optional, modifiers);
125127
signatureDeclarations.push(methodImplementingSignatures);
@@ -222,32 +224,17 @@ namespace ts.codefix {
222224
parameters.push(restParameter);
223225
}
224226

225-
return createStubbedMethod(
226-
modifiers,
227-
name,
228-
optional,
229-
/*typeParameters*/ undefined,
230-
parameters,
231-
/*returnType*/ undefined);
232-
}
233-
234-
export function createStubbedMethod(
235-
modifiers: ReadonlyArray<Modifier>,
236-
name: PropertyName,
237-
optional: boolean,
238-
typeParameters: ReadonlyArray<TypeParameterDeclaration> | undefined,
239-
parameters: ReadonlyArray<ParameterDeclaration>,
240-
returnType: TypeNode | undefined) {
241227
return createMethod(
242228
/*decorators*/ undefined,
243229
modifiers,
244230
/*asteriskToken*/ undefined,
245231
name,
246232
optional ? createToken(SyntaxKind.QuestionToken) : undefined,
247-
typeParameters,
233+
/*typeParameters*/ undefined,
248234
parameters,
249-
returnType,
250-
createStubbedMethodBody());
235+
/*returnType*/ undefined,
236+
createStubbedMethodBody(),
237+
);
251238
}
252239

253240
function createStubbedMethodBody() {

0 commit comments

Comments
 (0)