Resurrect SuppressAnyReturnType, but make it used only at the toplevel

This commit is contained in:
Eli Barzilay 2020-01-07 01:19:23 -05:00
parent 724f426468
commit 9fbcdb1edb
8 changed files with 16 additions and 18 deletions

View File

@ -4501,6 +4501,8 @@ namespace ts {
}
function signatureToSignatureDeclarationHelper(signature: Signature, kind: SyntaxKind, context: NodeBuilderContext): SignatureDeclaration {
const suppressAny = context.flags & NodeBuilderFlags.SuppressAnyReturnType;
if (suppressAny) context.flags &= ~NodeBuilderFlags.SuppressAnyReturnType; // suppress only toplevel `any`s
let typeParameters: TypeParameterDeclaration[] | undefined;
let typeArguments: TypeNode[] | undefined;
if (context.flags & NodeBuilderFlags.WriteTypeArgumentsOfSignature && signature.target && signature.mapper && signature.target.typeParameters) {
@ -4530,10 +4532,12 @@ namespace ts {
}
else {
const returnType = getReturnTypeOfSignature(signature);
returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context);
}
if (!returnTypeNode) {
returnTypeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword);
if (returnType && !(suppressAny && isTypeAny(returnType))) {
returnTypeNode = typeToTypeNodeHelper(returnType, context);
}
else if (!suppressAny) {
returnTypeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword);
}
}
context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum
return createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments);

View File

@ -3619,7 +3619,6 @@ 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
@ -3661,7 +3660,6 @@ 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)

View File

@ -155,7 +155,7 @@ namespace ts.codefix {
body: Block | undefined,
): MethodDeclaration | undefined {
const program = context.program;
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation, getNoopSymbolTrackerWithResolver(context));
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context));
if (!signatureDeclaration) {
return undefined;
}

View File

@ -2110,7 +2110,6 @@ declare namespace ts {
WriteTypeArgumentsOfSignature = 32,
UseFullyQualifiedType = 64,
UseOnlyExternalAliasing = 128,
/** @deprecated Ignored */
SuppressAnyReturnType = 256,
WriteTypeParametersInQualifiedName = 512,
MultilineObjectLiterals = 1024,
@ -2139,7 +2138,6 @@ declare namespace ts {
UseStructuralFallback = 8,
WriteTypeArgumentsOfSignature = 32,
UseFullyQualifiedType = 64,
/** @deprecated Ignored */
SuppressAnyReturnType = 256,
MultilineObjectLiterals = 1024,
WriteClassExpressionAsTypeLiteral = 2048,

View File

@ -2110,7 +2110,6 @@ declare namespace ts {
WriteTypeArgumentsOfSignature = 32,
UseFullyQualifiedType = 64,
UseOnlyExternalAliasing = 128,
/** @deprecated Ignored */
SuppressAnyReturnType = 256,
WriteTypeParametersInQualifiedName = 512,
MultilineObjectLiterals = 1024,
@ -2139,7 +2138,6 @@ declare namespace ts {
UseStructuralFallback = 8,
WriteTypeArgumentsOfSignature = 32,
UseFullyQualifiedType = 64,
/** @deprecated Ignored */
SuppressAnyReturnType = 256,
MultilineObjectLiterals = 1024,
WriteClassExpressionAsTypeLiteral = 2048,

View File

@ -43,7 +43,7 @@ abstract class AbstractCstVisitor {
): Set<this_will_be_collapsed>;
}
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): any {
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) {
throw new Error("Method not implemented.");
}
}`

View File

@ -43,11 +43,11 @@ class C implements I<number> {
throw new Error("Method not implemented.");
}
[Symbol.isConcatSpreadable]: boolean;
[Symbol.iterator](): any {
[Symbol.iterator]() {
throw new Error("Method not implemented.");
}
[Symbol.match]: boolean;
[Symbol.replace](...args: {}): any {
[Symbol.replace](...args: {}) {
throw new Error("Method not implemented.");
}
[Symbol.search](str: string): number {

View File

@ -5,7 +5,7 @@
//// y: number
//// z: number;
//// f(): number,
//// g()
//// g(): any
//// h();
////}
////
@ -19,7 +19,7 @@ verify.codeFix({
y: number
z: number;
f(): number,
g()
g(): any
h();
}
@ -30,10 +30,10 @@ class C1 implements I1 {
f(): number {
throw new Error("Method not implemented.");
}
g(): any {
g() {
throw new Error("Method not implemented.");
}
h(): any {
h() {
throw new Error("Method not implemented.");
}
}`,