diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a0a1dcaad17..ddf4a2ceadb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4532,13 +4532,7 @@ namespace ts { const returnType = getReturnTypeOfSignature(signature); returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); } - if (context.flags & NodeBuilderFlags.SuppressAnyReturnType - && kind !== SyntaxKind.FunctionType && kind !== SyntaxKind.ConstructorType) { - if (returnTypeNode && returnTypeNode.kind === SyntaxKind.AnyKeyword) { - returnTypeNode = undefined; - } - } - else if (!returnTypeNode) { + if (!returnTypeNode) { returnTypeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword); } context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 98f2531b6c6..036064bb64d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3619,6 +3619,7 @@ namespace ts { WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol + /** @deprecated Ignored */ SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type. WriteTypeParametersInQualifiedName = 1 << 9, MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines @@ -3660,6 +3661,7 @@ namespace ts { WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) // hole because `UseOnlyExternalAliasing` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` instead + /** @deprecated Ignored */ SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type. // hole because `WriteTypeParametersInQualifiedName` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` for this instead MultilineObjectLiterals = 1 << 10, // Always print object literals across multiple lines (only used to map into node builder flags) diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 95fc499a2f9..ed226acfdc2 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -155,7 +155,7 @@ namespace ts.codefix { body: Block | undefined, ): MethodDeclaration | undefined { const program = context.program; - const signatureDeclaration = program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context)); + const signatureDeclaration = program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation, getNoopSymbolTrackerWithResolver(context)); if (!signatureDeclaration) { return undefined; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 5ca50db8067..21d8d214498 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2110,6 +2110,7 @@ declare namespace ts { WriteTypeArgumentsOfSignature = 32, UseFullyQualifiedType = 64, UseOnlyExternalAliasing = 128, + /** @deprecated Ignored */ SuppressAnyReturnType = 256, WriteTypeParametersInQualifiedName = 512, MultilineObjectLiterals = 1024, @@ -2138,6 +2139,7 @@ declare namespace ts { UseStructuralFallback = 8, WriteTypeArgumentsOfSignature = 32, UseFullyQualifiedType = 64, + /** @deprecated Ignored */ SuppressAnyReturnType = 256, MultilineObjectLiterals = 1024, WriteClassExpressionAsTypeLiteral = 2048, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 1143d4c6ebc..cbbc5ff6d89 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2110,6 +2110,7 @@ declare namespace ts { WriteTypeArgumentsOfSignature = 32, UseFullyQualifiedType = 64, UseOnlyExternalAliasing = 128, + /** @deprecated Ignored */ SuppressAnyReturnType = 256, WriteTypeParametersInQualifiedName = 512, MultilineObjectLiterals = 1024, @@ -2138,6 +2139,7 @@ declare namespace ts { UseStructuralFallback = 8, WriteTypeArgumentsOfSignature = 32, UseFullyQualifiedType = 64, + /** @deprecated Ignored */ SuppressAnyReturnType = 256, MultilineObjectLiterals = 1024, WriteClassExpressionAsTypeLiteral = 2048, diff --git a/tests/cases/fourslash/codeFixClassExtendAbstractMethodWithLongName.ts b/tests/cases/fourslash/codeFixClassExtendAbstractMethodWithLongName.ts index dd2eb9c1709..bed8c7de913 100644 --- a/tests/cases/fourslash/codeFixClassExtendAbstractMethodWithLongName.ts +++ b/tests/cases/fourslash/codeFixClassExtendAbstractMethodWithLongName.ts @@ -43,7 +43,7 @@ abstract class AbstractCstVisitor { ): Set; } class CstVisitorImplementation extends AbstractCstVisitor { - Node(arg1: [some.really.long.generated.type.goes.here.you.know.this_.should.be.pretty.simple.Yah[], another.really.long.generated.type.goes.here.too.because.who.cares.about.space.do_.you.feel.me.Yah[]], arg2: [this_will_be_collapsed], arg3: any, arg4: this_is_fine) { + Node(arg1: [some.really.long.generated.type.goes.here.you.know.this_.should.be.pretty.simple.Yah[], another.really.long.generated.type.goes.here.too.because.who.cares.about.space.do_.you.feel.me.Yah[]], arg2: [this_will_be_collapsed], arg3: any, arg4: this_is_fine): any { throw new Error("Method not implemented."); } }` diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceComputedPropertyNameWellKnownSymbols.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceComputedPropertyNameWellKnownSymbols.ts index d87fcb73d4e..0c49f8b3d39 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfaceComputedPropertyNameWellKnownSymbols.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceComputedPropertyNameWellKnownSymbols.ts @@ -43,11 +43,11 @@ class C implements I { throw new Error("Method not implemented."); } [Symbol.isConcatSpreadable]: boolean; - [Symbol.iterator]() { + [Symbol.iterator](): any { throw new Error("Method not implemented."); } [Symbol.match]: boolean; - [Symbol.replace](...args: {}) { + [Symbol.replace](...args: {}): any { throw new Error("Method not implemented."); } [Symbol.search](str: string): number { diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceMultipleMembersAndPunctuation.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceMultipleMembersAndPunctuation.ts index bc52629e8e9..5e7f9acd7d3 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfaceMultipleMembersAndPunctuation.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceMultipleMembersAndPunctuation.ts @@ -4,7 +4,7 @@ //// x: number, //// y: number //// z: number; -//// f(), +//// f(): number, //// g() //// h(); ////} @@ -18,7 +18,7 @@ verify.codeFix({ x: number, y: number z: number; - f(), + f(): number, g() h(); } @@ -27,13 +27,13 @@ class C1 implements I1 { x: number; y: number; z: number; - f() { + f(): number { throw new Error("Method not implemented."); } - g() { + g(): any { throw new Error("Method not implemented."); } - h() { + h(): any { throw new Error("Method not implemented."); } }`, diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamMethod.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamMethod.ts index 70db2b5908c..68e294004e6 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamMethod.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamMethod.ts @@ -1,7 +1,7 @@ /// ////interface I { -//// f(x: T); +//// f(x: T): T; ////} ////class C implements I {} @@ -9,10 +9,10 @@ verify.codeFix({ description: "Implement interface 'I'", newFileContent: `interface I { - f(x: T); + f(x: T): T; } class C implements I { - f(x: T) { + f(x: T): T { throw new Error("Method not implemented."); } }`,