File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
src/transformer/descriptor/method Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 11import * as ts from 'typescript' ;
22import { GetReturnNodeFromBody } from './bodyReturnType' ;
33
4+ function isFunctionLikeDeclaration ( node : ts . SignatureDeclaration ) : node is ts . FunctionLikeDeclaration {
5+ switch ( true ) {
6+ case ts . isFunctionDeclaration ( node ) :
7+ case ts . isMethodDeclaration ( node ) :
8+ case ts . isGetAccessorDeclaration ( node ) :
9+ case ts . isSetAccessorDeclaration ( node ) :
10+ case ts . isConstructorDeclaration ( node ) :
11+ case ts . isFunctionExpression ( node ) :
12+ case ts . isArrowFunction ( node ) :
13+ return true ;
14+ }
15+
16+ return false ;
17+ }
18+
419export function GetFunctionReturnType ( node : ts . SignatureDeclaration ) : ts . Node {
5- if ( ts . isArrowFunction ( node ) || ts . isFunctionExpression ( node ) ) {
20+ const declaredReturnType : ts . TypeNode | undefined = node . type ;
21+ if ( declaredReturnType ) {
22+ return declaredReturnType ;
23+ }
24+
25+ if ( isFunctionLikeDeclaration ( node ) ) {
626 return GetReturnNodeFromBody ( node ) ;
727 }
828
9- if ( ! node . type ) {
29+ if ( ! declaredReturnType ) {
1030 throw new Error (
1131 `The transformer couldn't determine the type of ${ node . getText ( ) } . Did you declare its type?` ,
1232 ) ;
1333 }
1434
15- return node . type ;
35+ return declaredReturnType ;
1636}
You can’t perform that action at this time.
0 commit comments