@@ -502,27 +502,20 @@ module.exports = function propTypesInstructions(context, components, utils) {
502
502
this . referenceNameMap = new Set ( ) ;
503
503
this . sourceCode = context . getSourceCode ( ) ;
504
504
this . shouldIgnorePropTypes = false ;
505
- this . startWithTSTypeAnnotation ( ) ;
505
+ this . visitTSNode ( this . propTypes ) ;
506
506
this . endAndStructDeclaredPropTypes ( ) ;
507
507
}
508
508
509
- startWithTSTypeAnnotation ( ) {
510
- if ( astUtil . isTSTypeAnnotation ( this . propTypes ) ) {
511
- const typeAnnotation = this . propTypes . typeAnnotation ;
512
- this . visitTSNode ( typeAnnotation ) ;
513
- } else {
514
- // weird cases such as TSTypeFunction
515
- this . shouldIgnorePropTypes = true ;
516
- }
517
- }
518
-
519
509
/**
520
510
* The node will be distribute to different function.
521
511
* @param {ASTNode } node
522
512
*/
523
513
visitTSNode ( node ) {
524
514
if ( ! node ) return ;
525
- if ( astUtil . isTSTypeReference ( node ) ) {
515
+ if ( astUtil . isTSTypeAnnotation ( node ) ) {
516
+ const typeAnnotation = node . typeAnnotation ;
517
+ this . visitTSNode ( typeAnnotation ) ;
518
+ } else if ( astUtil . isTSTypeReference ( node ) ) {
526
519
this . searchDeclarationByName ( node ) ;
527
520
} else if ( astUtil . isTSInterfaceHeritage ( node ) ) {
528
521
this . searchDeclarationByName ( node ) ;
@@ -535,12 +528,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
535
528
this . convertIntersectionTypeToPropTypes ( node ) ;
536
529
} else if ( astUtil . isTSParenthesizedType ( node ) ) {
537
530
const typeAnnotation = node . typeAnnotation ;
538
- if ( astUtil . isTSTypeLiteral ( typeAnnotation ) ) {
539
- // Check node is an object literal
540
- if ( Array . isArray ( node . typeAnnotation . members ) ) {
541
- this . foundDeclaredPropertiesList = this . foundDeclaredPropertiesList
542
- . concat ( node . typeAnnotation . members ) ;
543
- }
531
+ this . visitTSNode ( typeAnnotation ) ;
532
+ } else if ( astUtil . isTSTypeParameterInstantiation ( node ) ) {
533
+ if ( Array . isArray ( node . params ) ) {
534
+ node . params . forEach ( this . visitTSNode , this ) ;
544
535
}
545
536
} else {
546
537
this . shouldIgnorePropTypes = true ;
@@ -671,6 +662,19 @@ module.exports = function propTypesInstructions(context, components, utils) {
671
662
switch ( res . type ) {
672
663
case 'ObjectExpression' :
673
664
iterateProperties ( context , res . properties , ( key , value , propNode ) => {
665
+ if ( propNode && propNode . argument && propNode . argument . type === 'CallExpression' ) {
666
+ if ( propNode . argument . typeParameters ) {
667
+ this . visitTSNode ( propNode . argument . typeParameters ) ;
668
+ } else {
669
+ // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
670
+ this . shouldIgnorePropTypes = true ;
671
+ return ;
672
+ }
673
+ }
674
+ if ( ! value ) {
675
+ this . shouldIgnorePropTypes = true ;
676
+ return ;
677
+ }
674
678
const types = buildReactDeclarationTypes ( value , key ) ;
675
679
types . fullName = key ;
676
680
types . name = key ;
@@ -679,6 +683,14 @@ module.exports = function propTypesInstructions(context, components, utils) {
679
683
this . declaredPropTypes [ key ] = types ;
680
684
} ) ;
681
685
break ;
686
+ case 'CallExpression' :
687
+ if ( res . typeParameters ) {
688
+ this . visitTSNode ( res . typeParameters ) ;
689
+ } else {
690
+ // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
691
+ this . shouldIgnorePropTypes = true ;
692
+ }
693
+ break ;
682
694
default :
683
695
}
684
696
}
@@ -689,15 +701,13 @@ module.exports = function propTypesInstructions(context, components, utils) {
689
701
// Handle ReturnType<()=>returnType>
690
702
if ( astUtil . isTSFunctionType ( returnType ) ) {
691
703
if ( astUtil . isTSTypeAnnotation ( returnType . returnType ) ) {
692
- const returnTypeAnnotation = returnType . returnType . typeAnnotation ;
693
- this . visitTSNode ( returnTypeAnnotation ) ;
704
+ this . visitTSNode ( returnType . returnType ) ;
694
705
return ;
695
706
}
696
707
// This line is trying to handle typescript-eslint-parser
697
708
// typescript-eslint-parser TSFunction name returnType as typeAnnotation
698
709
if ( astUtil . isTSTypeAnnotation ( returnType . typeAnnotation ) ) {
699
- const returnTypeAnnotation = returnType . typeAnnotation . typeAnnotation ;
700
- this . visitTSNode ( returnTypeAnnotation ) ;
710
+ this . visitTSNode ( returnType . typeAnnotation ) ;
701
711
return ;
702
712
}
703
713
}
0 commit comments