@@ -28,11 +28,16 @@ export interface DocEntry {
2828 type : string ;
2929 simplifiedType : string ;
3030
31- tags : Record < string , string > ;
31+ tags : RawTag [ ] ;
3232 required : boolean ;
3333 deprecated : boolean ;
3434}
3535
36+ export interface RawTag {
37+ name : string ;
38+ text : string ;
39+ }
40+
3641interface EntryContext {
3742 program : Project ;
3843 transform ?: Transformer ;
@@ -201,16 +206,21 @@ function getDocEntry(
201206 . getTypeChecker ( )
202207 . getTypeOfSymbolAtLocation ( prop , context . declaration ) ;
203208 const isOptional = prop . isOptional ( ) ;
204- const tags = Object . fromEntries (
205- prop
206- . getJsDocTags ( )
207- . map ( ( tag ) => [ tag . getName ( ) , ts . displayPartsToString ( tag . getText ( ) ) ] ) ,
209+ const tags = prop . getJsDocTags ( ) . map (
210+ ( tag ) =>
211+ ( {
212+ name : tag . getName ( ) ,
213+ text : ts . displayPartsToString ( tag . getText ( ) ) ,
214+ } ) satisfies RawTag ,
208215 ) ;
209216
210- let type = getFullType ( subType , isOptional ) ;
217+ let type = getFullType ( subType ) ;
211218
212- if ( 'remarks' in tags ) {
213- type = / ^ ` (?< name > .+ ) ` / . exec ( tags . remarks ) ?. [ 1 ] ?? type ;
219+ for ( const tag of tags ) {
220+ if ( tag . name !== 'remarks' ) continue ;
221+
222+ // replace type with @remarks
223+ type = / ^ ` (?< name > .+ ) ` / . exec ( tag . text ) ?. [ 1 ] ?? type ;
214224 }
215225
216226 const entry : DocEntry = {
@@ -222,37 +232,27 @@ function getDocEntry(
222232 ) ,
223233 tags,
224234 type,
225- simplifiedType : getSimpleForm ( subType , program . getTypeChecker ( ) ) ,
235+ simplifiedType : getSimpleForm (
236+ subType ,
237+ program . getTypeChecker ( ) ,
238+ isOptional ,
239+ ) ,
226240 required : ! isOptional ,
227- deprecated : prop
228- . getJsDocTags ( )
229- . some ( ( tag ) => tag . getName ( ) === 'deprecated' ) ,
241+ deprecated : tags . some ( ( tag ) => tag . name === 'deprecated' ) ,
230242 } ;
231243
232244 transform ?. call ( context , entry , subType , prop ) ;
233245
234246 return entry ;
235247}
236248
237- function getFullType ( type : Type , isOptional : boolean ) : string {
238- if ( type . isUnion ( ) && isOptional ) {
239- const t = type . compilerType as ts . UnionType ;
240- const originalTypes = t . types ;
241-
242- t . types = t . types . filter ( ( v ) => v . flags !== ts . TypeFlags . Undefined ) ;
243- const result = getFullType ( type , false ) ;
244- t . types = originalTypes ;
245-
246- return result ;
247- }
248-
249- let typeName = type
250- . getNonNullableType ( )
251- . getText (
252- undefined ,
253- ts . TypeFormatFlags . UseAliasDefinedOutsideCurrentScope &
254- ts . TypeFormatFlags . NoTruncation ,
255- ) ;
249+ function getFullType ( type : Type ) : string {
250+ let typeName = type . getText (
251+ undefined ,
252+ ts . TypeFormatFlags . UseAliasDefinedOutsideCurrentScope |
253+ ts . TypeFormatFlags . NoTruncation |
254+ ts . TypeFormatFlags . InTypeAlias ,
255+ ) ;
256256
257257 if ( type . getAliasSymbol ( ) && type . getAliasTypeArguments ( ) . length === 0 ) {
258258 typeName = type . getAliasSymbol ( ) ?. getEscapedName ( ) ?? typeName ;
0 commit comments