From 0c467d095f544953f7d7e44d7d6871f07b58f7e1 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Thu, 19 Dec 2019 15:11:04 -0500 Subject: [PATCH] Fix `signatureToSignatureDeclarationHelper` Even if `SuppressAnyReturnType` is on, don't supress it if it's a function. Fixes #35508. --- src/compiler/checker.ts | 3 +- .../codeFixClassImplementInterfaceCallback.ts | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/codeFixClassImplementInterfaceCallback.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dd431a50b6c..a0a1dcaad17 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4532,7 +4532,8 @@ namespace ts { const returnType = getReturnTypeOfSignature(signature); returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); } - if (context.flags & NodeBuilderFlags.SuppressAnyReturnType) { + if (context.flags & NodeBuilderFlags.SuppressAnyReturnType + && kind !== SyntaxKind.FunctionType && kind !== SyntaxKind.ConstructorType) { if (returnTypeNode && returnTypeNode.kind === SyntaxKind.AnyKeyword) { returnTypeNode = undefined; } diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceCallback.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceCallback.ts new file mode 100644 index 00000000000..65692ca013b --- /dev/null +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceCallback.ts @@ -0,0 +1,75 @@ +/// + +// #35508 + +////interface IFoo1 { +//// parse(reviver: () => any): void; +////} +//// +////class Foo1 implements IFoo1 { +////} +//// +////interface IFoo2 { +//// parse(reviver: { (): any }): void; +////} +//// +////class Foo2 implements IFoo2 { +////} +//// +////interface IFoo3 { +//// parse(reviver: new () => any): void; +////} +//// +////class Foo3 implements IFoo3 { +////} +//// +////interface IFoo4 { +//// parse(reviver: { new (): any }): void; +////} +//// +////class Foo4 implements IFoo4 { +////} + +verify.codeFixAll({ + fixAllDescription: ts.Diagnostics.Implement_all_unimplemented_interfaces.message, + fixId: "fixClassIncorrectlyImplementsInterface", + newFileContent: +`interface IFoo1 { + parse(reviver: () => any): void; +} + +class Foo1 implements IFoo1 { + parse(reviver: () => any): void { + throw new Error("Method not implemented."); + } +} + +interface IFoo2 { + parse(reviver: { (): any }): void; +} + +class Foo2 implements IFoo2 { + parse(reviver: () => any): void { + throw new Error("Method not implemented."); + } +} + +interface IFoo3 { + parse(reviver: new () => any): void; +} + +class Foo3 implements IFoo3 { + parse(reviver: new () => any): void { + throw new Error("Method not implemented."); + } +} + +interface IFoo4 { + parse(reviver: { new (): any }): void; +} + +class Foo4 implements IFoo4 { + parse(reviver: new () => any): void { + throw new Error("Method not implemented."); + } +}`});