* Gets the type of the function-like doc. If no explicit type has been specified, * the type checker is used to compute a type string based on the function body.
(doc: FunctionLikeDoc)
| 48 | * the type checker is used to compute a type string based on the function body. |
| 49 | */ |
| 50 | function getTypeOfFunctionLikeDoc(doc: FunctionLikeDoc): string | null { |
| 51 | if (doc.type) { |
| 52 | return doc.type; |
| 53 | } |
| 54 | |
| 55 | const decl = doc.declaration as ts.MethodDeclaration | ts.FunctionDeclaration; |
| 56 | const signature = doc.typeChecker.getSignatureFromDeclaration(decl); |
| 57 | |
| 58 | if (!signature) { |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | const returnType = doc.typeChecker.getReturnTypeOfSignature(signature); |
| 63 | return doc.typeChecker.typeToString(returnType); |
| 64 | } |
| 65 | |
| 66 | /** Whether the given API doc is a function-like doc. */ |
| 67 | function isFunctionLikeDoc(doc: ApiDoc): doc is FunctionLikeDoc { |