Skip to content

Commit 724f426

Browse files
committed
Remove SuppressAnyReturnType
Following a discussion with Ryan, it seems best to leave any `any`s in the generated code.
1 parent 0c467d0 commit 724f426

9 files changed

+19
-19
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4532,13 +4532,7 @@ namespace ts {
45324532
const returnType = getReturnTypeOfSignature(signature);
45334533
returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context);
45344534
}
4535-
if (context.flags & NodeBuilderFlags.SuppressAnyReturnType
4536-
&& kind !== SyntaxKind.FunctionType && kind !== SyntaxKind.ConstructorType) {
4537-
if (returnTypeNode && returnTypeNode.kind === SyntaxKind.AnyKeyword) {
4538-
returnTypeNode = undefined;
4539-
}
4540-
}
4541-
else if (!returnTypeNode) {
4535+
if (!returnTypeNode) {
45424536
returnTypeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword);
45434537
}
45444538
context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,7 @@ 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 */
36223623
SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type.
36233624
WriteTypeParametersInQualifiedName = 1 << 9,
36243625
MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines
@@ -3660,6 +3661,7 @@ namespace ts {
36603661
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
36613662
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
36623663
// hole because `UseOnlyExternalAliasing` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` instead
3664+
/** @deprecated Ignored */
36633665
SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type.
36643666
// hole because `WriteTypeParametersInQualifiedName` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` for this instead
36653667
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 | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context));
158+
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation, getNoopSymbolTrackerWithResolver(context));
159159
if (!signatureDeclaration) {
160160
return undefined;
161161
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,7 @@ declare namespace ts {
21102110
WriteTypeArgumentsOfSignature = 32,
21112111
UseFullyQualifiedType = 64,
21122112
UseOnlyExternalAliasing = 128,
2113+
/** @deprecated Ignored */
21132114
SuppressAnyReturnType = 256,
21142115
WriteTypeParametersInQualifiedName = 512,
21152116
MultilineObjectLiterals = 1024,
@@ -2138,6 +2139,7 @@ declare namespace ts {
21382139
UseStructuralFallback = 8,
21392140
WriteTypeArgumentsOfSignature = 32,
21402141
UseFullyQualifiedType = 64,
2142+
/** @deprecated Ignored */
21412143
SuppressAnyReturnType = 256,
21422144
MultilineObjectLiterals = 1024,
21432145
WriteClassExpressionAsTypeLiteral = 2048,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,7 @@ declare namespace ts {
21102110
WriteTypeArgumentsOfSignature = 32,
21112111
UseFullyQualifiedType = 64,
21122112
UseOnlyExternalAliasing = 128,
2113+
/** @deprecated Ignored */
21132114
SuppressAnyReturnType = 256,
21142115
WriteTypeParametersInQualifiedName = 512,
21152116
MultilineObjectLiterals = 1024,
@@ -2138,6 +2139,7 @@ declare namespace ts {
21382139
UseStructuralFallback = 8,
21392140
WriteTypeArgumentsOfSignature = 32,
21402141
UseFullyQualifiedType = 64,
2142+
/** @deprecated Ignored */
21412143
SuppressAnyReturnType = 256,
21422144
MultilineObjectLiterals = 1024,
21432145
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) {
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 {
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]() {
46+
[Symbol.iterator](): any {
4747
throw new Error("Method not implemented.");
4848
}
4949
[Symbol.match]: boolean;
50-
[Symbol.replace](...args: {}) {
50+
[Symbol.replace](...args: {}): any {
5151
throw new Error("Method not implemented.");
5252
}
5353
[Symbol.search](str: string): number {

tests/cases/fourslash/codeFixClassImplementInterfaceMultipleMembersAndPunctuation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//// x: number,
55
//// y: number
66
//// z: number;
7-
//// f(),
7+
//// f(): number,
88
//// g()
99
//// h();
1010
////}
@@ -18,7 +18,7 @@ verify.codeFix({
1818
x: number,
1919
y: number
2020
z: number;
21-
f(),
21+
f(): number,
2222
g()
2323
h();
2424
}
@@ -27,13 +27,13 @@ class C1 implements I1 {
2727
x: number;
2828
y: number;
2929
z: number;
30-
f() {
30+
f(): number {
3131
throw new Error("Method not implemented.");
3232
}
33-
g() {
33+
g(): any {
3434
throw new Error("Method not implemented.");
3535
}
36-
h() {
36+
h(): any {
3737
throw new Error("Method not implemented.");
3838
}
3939
}`,

tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamMethod.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/// <reference path='fourslash.ts' />
22

33
////interface I {
4-
//// f<T extends number>(x: T);
4+
//// f<T extends number>(x: T): T;
55
////}
66
////class C implements I {}
77

88
verify.codeFix({
99
description: "Implement interface 'I'",
1010
newFileContent:
1111
`interface I {
12-
f<T extends number>(x: T);
12+
f<T extends number>(x: T): T;
1313
}
1414
class C implements I {
15-
f<T extends number>(x: T) {
15+
f<T extends number>(x: T): T {
1616
throw new Error("Method not implemented.");
1717
}
1818
}`,

0 commit comments

Comments
 (0)