@@ -533,7 +533,7 @@ export class Parser {
533
533
const jsDocComment = this . findDocComment ( prop ) ;
534
534
const hasCodeBasedDefault = defaultProps [ propName ] !== undefined ;
535
535
536
- let defaultValue = null ;
536
+ let defaultValue : { value : any } | null = null ;
537
537
538
538
if ( hasCodeBasedDefault ) {
539
539
defaultValue = { value : defaultProps [ propName ] } ;
@@ -546,26 +546,36 @@ export class Parser {
546
546
const stored = result [ propName ] ;
547
547
const type = this . getDocgenType ( propType ) ;
548
548
549
+ function addToUnion ( union : string , toAdd : string ) {
550
+ const set = new Set ( union . split ( " | " ) ) ;
551
+ toAdd . split ( " | " ) . map ( item => set . add ( item ) )
552
+ return Array . from ( set ) . join ( " | " ) ;
553
+ }
554
+
549
555
if ( stored ) {
550
556
if ( jsDocComment . fullComment ) {
551
- stored . description = result [ propName ] . description
552
- ? `${ result [ propName ] . description } \n${ jsDocComment . fullComment } `
553
- : jsDocComment . fullComment ;
557
+ stored . description =
558
+ stored . description &&
559
+ stored . description . indexOf ( jsDocComment . fullComment ) === - 1
560
+ ? `${ stored . description } \n${ jsDocComment . fullComment } `
561
+ : jsDocComment . fullComment ;
554
562
}
555
563
556
564
if ( ! stored . type ) {
557
565
stored . type = type ;
558
- } else if ( stored . type . name . split ( ' | ' ) . indexOf ( type . name ) === - 1 ) {
559
- stored . type . name += ` | ${ this . getDocgenType ( propType ) . name } ` ;
566
+ } else if ( stored . type . name . split ( " | " ) . indexOf ( type . name ) === - 1 ) {
567
+ stored . type . name = addToUnion (
568
+ stored . type . name ,
569
+ this . getDocgenType ( propType ) . name
570
+ ) ;
560
571
}
561
572
562
573
if ( defaultValue ) {
563
574
if ( ! stored . defaultValue ) {
564
575
stored . defaultValue = defaultValue ;
565
- } else if (
566
- stored . defaultValue . value . indexOf ( defaultValue . value ) === - 1
567
- ) {
568
- stored . defaultValue += ` | ${ defaultValue } ` ;
576
+ } else {
577
+ const value = String ( stored . defaultValue . value ) ;
578
+ stored . defaultValue . value = addToUnion ( value , String ( defaultValue . value ) ) ;
569
579
}
570
580
}
571
581
@@ -579,7 +589,7 @@ export class Parser {
579
589
name : propName ,
580
590
parent,
581
591
required,
582
- type
592
+ type,
583
593
} ;
584
594
}
585
595
} ) ;
0 commit comments