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;
}