Skip to content

Commit 9fbcdb1

Browse files
committed
Resurrect SuppressAnyReturnType, but make it used only at the toplevel
1 parent 724f426 commit 9fbcdb1

File tree

8 files changed

+16
-18
lines changed

8 files changed

+16
-18
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,6 +4501,8 @@ namespace ts {
45014501
}
45024502

45034503
function signatureToSignatureDeclarationHelper(signature: Signature, kind: SyntaxKind, context: NodeBuilderContext): SignatureDeclaration {
4504+
const suppressAny = context.flags & NodeBuilderFlags.SuppressAnyReturnType;
4505+
if (suppressAny) context.flags &= ~NodeBuilderFlags.SuppressAnyReturnType; // suppress only toplevel `any`s
45044506
let typeParameters: TypeParameterDeclaration[] | undefined;
45054507
let typeArguments: TypeNode[] | undefined;
45064508
if (context.flags & NodeBuilderFlags.WriteTypeArgumentsOfSignature && signature.target && signature.mapper && signature.target.typeParameters) {
@@ -4530,10 +4532,12 @@ namespace ts {
45304532
}
45314533
else {
45324534
const returnType = getReturnTypeOfSignature(signature);
4533-
returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context);
4534-
}
4535-
if (!returnTypeNode) {
4536-
returnTypeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword);
4535+
if (returnType && !(suppressAny && isTypeAny(returnType))) {
4536+
returnTypeNode = typeToTypeNodeHelper(returnType, context);
4537+
}
4538+
else if (!suppressAny) {
4539+
returnTypeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword);
4540+
}
45374541
}
45384542
context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum
45394543
return createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments);

src/compiler/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,7 +3619,6 @@ namespace ts {
36193619
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
36203620
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
36213621
UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol
3622-
/** @deprecated Ignored */
36233622
SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type.
36243623
WriteTypeParametersInQualifiedName = 1 << 9,
36253624
MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines
@@ -3661,7 +3660,6 @@ namespace ts {
36613660
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
36623661
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
36633662
// hole because `UseOnlyExternalAliasing` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` instead
3664-
/** @deprecated Ignored */
36653663
SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type.
36663664
// hole because `WriteTypeParametersInQualifiedName` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` for this instead
36673665
MultilineObjectLiterals = 1 << 10, // Always print object literals across multiple lines (only used to map into node builder flags)

src/services/codefixes/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ namespace ts.codefix {
155155
body: Block | undefined,
156156
): MethodDeclaration | undefined {
157157
const program = context.program;
158-
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation, getNoopSymbolTrackerWithResolver(context));
158+
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context));
159159
if (!signatureDeclaration) {
160160
return undefined;
161161
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,6 @@ declare namespace ts {
21102110
WriteTypeArgumentsOfSignature = 32,
21112111
UseFullyQualifiedType = 64,
21122112
UseOnlyExternalAliasing = 128,
2113-
/** @deprecated Ignored */
21142113
SuppressAnyReturnType = 256,
21152114
WriteTypeParametersInQualifiedName = 512,
21162115
MultilineObjectLiterals = 1024,
@@ -2139,7 +2138,6 @@ declare namespace ts {
21392138
UseStructuralFallback = 8,
21402139
WriteTypeArgumentsOfSignature = 32,
21412140
UseFullyQualifiedType = 64,
2142-
/** @deprecated Ignored */
21432141
SuppressAnyReturnType = 256,
21442142
MultilineObjectLiterals = 1024,
21452143
WriteClassExpressionAsTypeLiteral = 2048,

tests/baselines/reference/api/typescript.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,6 @@ declare namespace ts {
21102110
WriteTypeArgumentsOfSignature = 32,
21112111
UseFullyQualifiedType = 64,
21122112
UseOnlyExternalAliasing = 128,
2113-
/** @deprecated Ignored */
21142113
SuppressAnyReturnType = 256,
21152114
WriteTypeParametersInQualifiedName = 512,
21162115
MultilineObjectLiterals = 1024,
@@ -2139,7 +2138,6 @@ declare namespace ts {
21392138
UseStructuralFallback = 8,
21402139
WriteTypeArgumentsOfSignature = 32,
21412140
UseFullyQualifiedType = 64,
2142-
/** @deprecated Ignored */
21432141
SuppressAnyReturnType = 256,
21442142
MultilineObjectLiterals = 1024,
21452143
WriteClassExpressionAsTypeLiteral = 2048,

tests/cases/fourslash/codeFixClassExtendAbstractMethodWithLongName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class AbstractCstVisitor {
4343
): Set<this_will_be_collapsed>;
4444
}
4545
class CstVisitorImplementation extends AbstractCstVisitor {
46-
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 {
46+
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) {
4747
throw new Error("Method not implemented.");
4848
}
4949
}`

tests/cases/fourslash/codeFixClassImplementInterfaceComputedPropertyNameWellKnownSymbols.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class C implements I<number> {
4343
throw new Error("Method not implemented.");
4444
}
4545
[Symbol.isConcatSpreadable]: boolean;
46-
[Symbol.iterator](): any {
46+
[Symbol.iterator]() {
4747
throw new Error("Method not implemented.");
4848
}
4949
[Symbol.match]: boolean;
50-
[Symbol.replace](...args: {}): any {
50+
[Symbol.replace](...args: {}) {
5151
throw new Error("Method not implemented.");
5252
}
5353
[Symbol.search](str: string): number {

tests/cases/fourslash/codeFixClassImplementInterfaceMultipleMembersAndPunctuation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//// y: number
66
//// z: number;
77
//// f(): number,
8-
//// g()
8+
//// g(): any
99
//// h();
1010
////}
1111
////
@@ -19,7 +19,7 @@ verify.codeFix({
1919
y: number
2020
z: number;
2121
f(): number,
22-
g()
22+
g(): any
2323
h();
2424
}
2525
@@ -30,10 +30,10 @@ class C1 implements I1 {
3030
f(): number {
3131
throw new Error("Method not implemented.");
3232
}
33-
g(): any {
33+
g() {
3434
throw new Error("Method not implemented.");
3535
}
36-
h(): any {
36+
h() {
3737
throw new Error("Method not implemented.");
3838
}
3939
}`,

0 commit comments

Comments
 (0)