@@ -9,7 +9,10 @@ function getNamesCompareFn(name) {
9
9
}
10
10
11
11
class APIDocVisitor {
12
- constructor ( fileNames ) { this . program = ts . createProgram ( fileNames , { } ) ; }
12
+ constructor ( fileNames ) {
13
+ this . program = ts . createProgram ( fileNames , { } ) ;
14
+ this . typeChecker = this . program . getTypeChecker ( true ) ;
15
+ }
13
16
14
17
15
18
visitSourceFile ( fileName ) {
@@ -105,7 +108,7 @@ class APIDocVisitor {
105
108
return {
106
109
name : inArgs . length ? inArgs [ 0 ] . text : property . name . text ,
107
110
defaultValue : property . initializer ? this . stringifyDefaultValue ( property . initializer ) : undefined ,
108
- type : this . stringifyTypeInfo ( property . type ) ,
111
+ type : this . typeChecker . typeToString ( this . typeChecker . getTypeAtLocation ( property ) ) ,
109
112
description : ts . displayPartsToString ( property . symbol . getDocumentationComment ( ) )
110
113
} ;
111
114
}
@@ -144,27 +147,6 @@ class APIDocVisitor {
144
147
145
148
return null ;
146
149
}
147
-
148
- stringifyTypeInfo ( type ) {
149
- // TODO: this is probably covered by some helper method in TS, investigate
150
-
151
- if ( ! type ) {
152
- return undefined ;
153
- }
154
-
155
- switch ( type . kind ) {
156
- case ts . SyntaxKind . BooleanKeyword :
157
- return 'boolean' ;
158
- case ts . SyntaxKind . NumberKeyword :
159
- return 'number' ;
160
- case ts . SyntaxKind . StringKeyword :
161
- return 'string' ;
162
- case ts . SyntaxKind . UnionType :
163
- return type . types . map ( ( typeNode ) => { return this . stringifyTypeInfo ( typeNode ) ; } ) . join ( ' | ' ) ;
164
- default :
165
- return 'unknown' ;
166
- }
167
- }
168
150
}
169
151
170
152
function parseOutApiDocs ( programFiles ) {
0 commit comments