import * as ts from 'typescript' ; const program = ts . createProgram ( [ 'fixtures/class.ts' ] , { } ) ; const checker = program . getTypeChecker ( ) ; const source = program . getSourceFile ( 'fixtures/class.ts' ) ; if ( source ) { console . log ( '# Exported Class List\n' ) ; ts . forEachChild ( source , function next ( node ) { if ( isExported ( node ) && ts . isClassDeclaration ( node ) && node . name ) { const type = checker . getTypeAtLocation ( node ) ; const ctorSymbol = checker . getSymbolAtLocation ( node . name ) ; if ( ! ctorSymbol ) return ; console . log ( printClassDoc ( type , ctorSymbol ) ) ; } } ) ; } function printClassDoc ( type , ctorSymbol ) { let buf = '## ' + ctorSymbol . name + '\n' ; const ctorType = checker . getTypeOfSymbolAtLocation ( ctorSymbol , ctorSymbol . valueDeclaration ! ) ; ctorType . getConstructSignatures ( ) . forEach ( sig => { const params = sig . parameters . map ( serializeSymbol ) ; const ret = checker . typeToString ( sig . getReturnType ( ) ) ; buf += '\nnew (' + params . join ( ', ' ) + ') => ' + ret + '\n' ; } ) ; buf += '\n### Properties\n' ; type . getProperties ( ) . forEach ( p => { buf += '\n- ' + serializeSymbol ( p ) ; } ) ; return buf + '\n' ; } function serializeSymbol ( symbol ) { const type = checker . getTypeOfSymbolAtLocation ( symbol , symbol . valueDeclaration ! ) ; return symbol . name + ': ' + checker . typeToString ( type ) ; } function isExported ( node ) { return ( ts . getCombinedModifierFlags ( node ) & ts . ModifierFlags . Export ) !== 0 ; }