@@ -25,7 +25,7 @@ export function getNodeSignature(node: DenoDocNode): string | null {
2525 return `${ asyncStr } function ${ name } ${ typeParamsStr } (${ params } ): ${ ret } `
2626 }
2727 case 'class' : {
28- const ext = node . classDef ?. extends ? ` extends ${ formatType ( node . classDef . extends ) } ` : ''
28+ const ext = node . classDef ?. extends ? ` extends ${ node . classDef . extends } ` : ''
2929 const impl = node . classDef ?. implements ?. map ( t => formatType ( t ) ) . join ( ', ' )
3030 const implStr = impl ? ` implements ${ impl } ` : ''
3131 const abstractStr = node . classDef ?. isAbstract ? 'abstract ' : ''
@@ -72,9 +72,6 @@ export function formatParam(param: FunctionParam): string {
7272export function formatType ( type ?: TsType ) : string {
7373 if ( ! type ) return ''
7474
75- // Strip ANSI codes from repr (deno doc may include terminal colors since it's built for that)
76- if ( type . repr ) return stripAnsi ( type . repr )
77-
7875 if ( type . kind === 'keyword' && type . keyword ) {
7976 return type . keyword
8077 }
@@ -92,5 +89,41 @@ export function formatType(type?: TsType): string {
9289 return type . union . map ( t => formatType ( t ) ) . join ( ' | ' )
9390 }
9491
92+ if ( type . kind === 'this' ) {
93+ return 'this'
94+ }
95+
96+ if ( type . kind === 'indexedAccess' && type . indexedAccess ) {
97+ return `${ formatType ( type . indexedAccess . objType ) } [${ formatType ( type . indexedAccess . indexType ) } ]`
98+ }
99+
100+ if ( type . kind === 'typeOperator' && type . typeOperator ) {
101+ return `${ type . typeOperator . operator } ${ formatType ( type . typeOperator . tsType ) } `
102+ }
103+
104+ if ( type . kind === 'fnOrConstructor' && type . fnOrConstructor ) {
105+ const { fnOrConstructor : fn } = type
106+ const typeParams = fn . typeParams ?. map ( t => t . name ) . join ( ', ' )
107+ const typeParamsStr = typeParams ? `<${ typeParams } >` : ''
108+ const params = fn . params . map ( p => formatParam ( p ) ) . join ( ', ' )
109+ const ret = formatType ( fn . tsType ) || 'void'
110+ return `${ typeParamsStr } (${ params } ) => ${ ret } `
111+ }
112+
113+ if ( type . kind === 'typeLiteral' && type . typeLiteral ) {
114+ const parts : string [ ] = [ ]
115+ for ( const prop of type . typeLiteral . properties ) {
116+ const opt = prop . optional ? '?' : ''
117+ const ro = prop . readonly ? 'readonly ' : ''
118+ parts . push ( `${ ro } ${ prop . name } ${ opt } : ${ formatType ( prop . tsType ) || 'unknown' } ` )
119+ }
120+ for ( const method of type . typeLiteral . methods ) {
121+ const params = method . params ?. map ( p => formatParam ( p ) ) . join ( ', ' ) || ''
122+ const ret = formatType ( method . returnType ) || 'void'
123+ parts . push ( `${ method . name } (${ params } ): ${ ret } ` )
124+ }
125+ return `{ ${ parts . join ( '; ' ) } }`
126+ }
127+
95128 return type . repr ? stripAnsi ( type . repr ) : 'unknown'
96129}
0 commit comments