@@ -158,12 +158,29 @@ function createTsc(srcFiles) {
158158
159159 function addType ( node ) {
160160 let typeStr ;
161- if ( tsc . isFunctionLike ( node ) ) {
162- const funcType = typeChecker . getTypeAtLocation ( node ) ;
163- const funcSignature = typeChecker . getSignaturesOfType ( funcType , tsc . SignatureKind . Call ) [ 0 ] ;
164- typeStr = typeChecker . typeToString ( funcSignature . getReturnType ( ) ,
161+ if ( tsc . isSetAccessor ( node ) ||
162+ tsc . isGetAccessor ( node ) ||
163+ tsc . isConstructSignatureDeclaration ( node ) ||
164+ tsc . isMethodDeclaration ( node ) ||
165+ tsc . isFunctionDeclaration ( node ) ||
166+ tsc . isConstructorDeclaration ( node ) ) {
167+ const signature = typeChecker . getSignatureFromDeclaration ( node ) ;
168+ const returnType = typeChecker . getReturnTypeOfSignature ( signature ) ;
169+ typeStr = typeChecker . typeToString ( returnType ,
165170 tsc . TypeFormatFlags . NoTruncation | tsc . TypeFormatFlags . InTypeAlias
166171 ) ;
172+ } else if ( tsc . isFunctionLike ( node ) ) {
173+ const funcType = typeChecker . getTypeAtLocation ( node ) ;
174+ const funcSignature = typeChecker . getSignaturesOfType ( funcType , tsc . SignatureKind . Call ) [ 0 ] ;
175+ if ( funcSignature ) {
176+ typeStr = typeChecker . typeToString ( funcSignature . getReturnType ( ) ,
177+ tsc . TypeFormatFlags . NoTruncation | tsc . TypeFormatFlags . InTypeAlias
178+ ) ;
179+ } else {
180+ typeStr = typeChecker . typeToString ( typeChecker . getTypeAtLocation ( node ) , node ,
181+ tsc . TypeFormatFlags . NoTruncation | tsc . TypeFormatFlags . InTypeAlias
182+ ) ;
183+ }
167184 } else {
168185 typeStr = typeChecker . typeToString ( typeChecker . getTypeAtLocation ( node ) , node ,
169186 tsc . TypeFormatFlags . NoTruncation | tsc . TypeFormatFlags . InTypeAlias
@@ -203,7 +220,7 @@ const createJSAst = async (options) => {
203220 if ( ts ) {
204221 const tsAst = ts . program . getSourceFile ( file ) ;
205222 tsc . forEachChild ( tsAst , ts . addType ) ;
206- writeTypesFile ( tsAst . fileName , ts . seenTypes , options ) ;
223+ writeTypesFile ( file , ts . seenTypes , options ) ;
207224 }
208225 } catch ( err ) {
209226 console . error ( file , err . message ) ;
0 commit comments