diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 248df02cfb9..5ed3136e64d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -94,6 +94,7 @@ namespace ts { getExportSpecifierLocalTargetSymbol, getTypeAtLocation: getTypeOfNode, getPropertySymbolOfDestructuringAssignment, + signatureToString, typeToString, getSymbolDisplayBuilder, symbolToString, @@ -2674,6 +2675,11 @@ namespace ts { } function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { + const returnType = getReturnTypeOfSignature(signature); + if (flags & TypeFormatFlags.supressAnyReturnType && isTypeAny(returnType)) { + return; + } + if (flags & TypeFormatFlags.WriteArrowStyleSignature) { writeSpace(writer); writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); @@ -2687,7 +2693,6 @@ namespace ts { buildTypePredicateDisplay(signature.typePredicate, writer, enclosingDeclaration, flags, symbolStack); } else { - const returnType = getReturnTypeOfSignature(signature); buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack); } } @@ -4136,7 +4141,7 @@ namespace ts { return type; } - function getTypeWithThisArgument(type: Type, thisArgument?: Type) { + function getTypeWithThisArgument(type: Type, thisArgument?: Type): Type { if (getObjectFlags(type) & ObjectFlags.Reference) { return createTypeReference((type).target, concatenate((type).typeArguments, [thisArgument || (type).target.thisType])); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index afebe57aeed..085895f3387 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2257,7 +2257,7 @@ namespace ts { getNonNullableType(type: Type): Type; getIntersectionType(types: Type[], aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type; getUnionType(types: Type[], subtypeReduction?: boolean, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type; - + getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; getSymbolOfNode(node: Node): Symbol; getSymbolAtLocation(node: Node): Symbol; @@ -2267,6 +2267,7 @@ namespace ts { getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol; getTypeAtLocation(node: Node): Type; getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): Type; + signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; getSymbolDisplayBuilder(): SymbolDisplayBuilder; @@ -2348,6 +2349,7 @@ namespace ts { InFirstTypeArgument = 0x00000100, // Writing first type argument of the instantiated type InTypeAlias = 0x00000200, // Writing type in type alias declaration UseTypeAliasValue = 0x00000400, // Serialize the type instead of using type-alias. This is needed when we emit declaration file. + supressAnyReturnType = 0x00000800, // If the return type is any-like, don't offer a return type. } export const enum SymbolFormatFlags {