@@ -32,14 +32,7 @@ export class FunctionExtractor {
3232 // TODO: is there any real situation in which the signature would not be available here?
3333 // Is void a better type?
3434 const signature = this . typeChecker . getSignatureFromDeclaration ( this . exportDeclaration ) ;
35- const returnType = signature
36- ? this . typeChecker . typeToString (
37- this . typeChecker . getReturnTypeOfSignature ( signature ) ,
38- undefined ,
39- // This ensures that e.g. `T | undefined` is not reduced to `T`.
40- ts . TypeFormatFlags . NoTypeReduction | ts . TypeFormatFlags . NoTruncation ,
41- )
42- : 'unknown' ;
35+ const returnType = signature ? extractReturnType ( signature , this . typeChecker ) : 'unknown' ;
4336
4437 const implementation =
4538 findImplementationOfFunction ( this . exportDeclaration , this . typeChecker ) ??
@@ -149,15 +142,24 @@ export function extractCallSignatures(name: string, typeChecker: ts.TypeChecker,
149142 jsdocTags : extractJsDocTags ( decl ) ,
150143 params : extractAllParams ( decl . parameters , typeChecker ) ,
151144 rawComment : extractRawJsDoc ( decl ) ,
152- returnType : typeChecker . typeToString (
153- typeChecker . getReturnTypeOfSignature ( signature ) ,
154- undefined ,
155- // This ensures that e.g. `T | undefined` is not reduced to `T`.
156- ts . TypeFormatFlags . NoTypeReduction | ts . TypeFormatFlags . NoTruncation ,
157- ) ,
145+ returnType : extractReturnType ( signature , typeChecker ) ,
158146 } ) ) ;
159147}
160148
149+ function extractReturnType ( signature : ts . Signature , typeChecker : ts . TypeChecker ) : string {
150+ // Handling Type Predicates
151+ if ( signature ?. declaration ?. type && ts . isTypePredicateNode ( signature . declaration . type ) ) {
152+ return signature . declaration . type . getText ( ) ;
153+ }
154+
155+ return typeChecker . typeToString (
156+ typeChecker . getReturnTypeOfSignature ( signature ) ,
157+ undefined ,
158+ // This ensures that e.g. `T | undefined` is not reduced to `T`.
159+ ts . TypeFormatFlags . NoTypeReduction | ts . TypeFormatFlags . NoTruncation ,
160+ ) ;
161+ }
162+
161163/** Finds the implementation of the given function declaration overload signature. */
162164export function findImplementationOfFunction (
163165 node : FunctionLike ,
0 commit comments