@@ -639,8 +639,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
639
639
typeName = node . typeName . name ;
640
640
const leftMostName = getLeftMostTypeName ( node . typeName ) ;
641
641
const shouldTraverseTypeParams = genericReactTypesImport . has ( leftMostName ) ;
642
- const nodeTypeParams = node . typeParameters ;
643
- if ( shouldTraverseTypeParams && nodeTypeParams && nodeTypeParams . length !== 0 ) {
642
+ const nodeTypeArguments = propsUtil . getTypeArguments ( node ) ;
643
+ if ( shouldTraverseTypeParams && nodeTypeArguments && nodeTypeArguments . length !== 0 ) {
644
644
// All react Generic types are derived from:
645
645
// type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
646
646
// So we should construct an optional children prop
@@ -662,7 +662,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
662
662
const idx = genericTypeParamIndexWherePropsArePresent [
663
663
leftMostName !== rightMostName ? rightMostName : importedName
664
664
] ;
665
- const nextNode = nodeTypeParams . params [ idx ] ;
665
+ const nextNode = nodeTypeArguments . params [ idx ] ;
666
666
this . visitTSNode ( nextNode ) ;
667
667
return ;
668
668
}
@@ -759,10 +759,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
759
759
760
760
convertReturnTypeToPropTypes ( node , rootNode ) {
761
761
// ReturnType<T> should always have one parameter
762
- const nodeTypeParams = node . typeParameters ;
763
- if ( nodeTypeParams ) {
764
- if ( nodeTypeParams . params . length === 1 ) {
765
- let returnType = nodeTypeParams . params [ 0 ] ;
762
+ const nodeTypeArguments = propsUtil . getTypeArguments ( node ) ;
763
+ if ( nodeTypeArguments ) {
764
+ if ( nodeTypeArguments . params . length === 1 ) {
765
+ let returnType = nodeTypeArguments . params [ 0 ] ;
766
766
// This line is trying to handle typescript-eslint-parser
767
767
// typescript-eslint-parser TSTypeQuery is wrapped by TSTypeReference
768
768
if ( astUtil . isTSTypeReference ( returnType ) ) {
@@ -794,9 +794,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
794
794
case 'ObjectExpression' :
795
795
iterateProperties ( context , res . properties , ( key , value , propNode ) => {
796
796
if ( propNode && astUtil . isCallExpression ( propNode . argument ) ) {
797
- const propNodeTypeParams = propNode . argument . typeParameters ;
798
- if ( propNodeTypeParams ) {
799
- this . visitTSNode ( propNodeTypeParams ) ;
797
+ const propNodeTypeArguments = propsUtil . getTypeArguments ( propNode . argument ) ;
798
+ if ( propNodeTypeArguments ) {
799
+ this . visitTSNode ( propNodeTypeArguments ) ;
800
800
} else {
801
801
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
802
802
this . shouldIgnorePropTypes = true ;
@@ -816,8 +816,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
816
816
} ) ;
817
817
break ;
818
818
case 'CallExpression' :
819
- if ( res . typeParameters ) {
820
- this . visitTSNode ( res . typeParameters ) ;
819
+ if ( propsUtil . getTypeArguments ( res ) ) {
820
+ this . visitTSNode ( propsUtil . getTypeArguments ( res ) ) ;
821
821
} else {
822
822
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
823
823
this . shouldIgnorePropTypes = true ;
@@ -1002,9 +1002,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
1002
1002
break ;
1003
1003
case 'GenericTypeAnnotation' :
1004
1004
if ( propTypes . id . name === '$ReadOnly' ) {
1005
- const propTypeParams = propTypes . typeParameters ;
1005
+ const propTypeArguments = propsUtil . getTypeArguments ( propTypes ) ;
1006
1006
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation (
1007
- propTypeParams . params [ 0 ] ,
1007
+ propTypeArguments . params [ 0 ] ,
1008
1008
declaredPropTypes
1009
1009
) ;
1010
1010
} else {
@@ -1041,11 +1041,16 @@ module.exports = function propTypesInstructions(context, components, utils) {
1041
1041
return ;
1042
1042
}
1043
1043
1044
+ let propTypesArguments = null ;
1045
+ if ( node . parent ) {
1046
+ propTypesArguments = propsUtil . getTypeArguments ( node . parent ) ;
1047
+ }
1048
+
1044
1049
if (
1045
1050
node . parent
1046
1051
&& node . parent . callee
1047
- && node . parent . typeParameters
1048
- && node . parent . typeParameters . params
1052
+ && propTypesArguments
1053
+ && propTypesArguments . params
1049
1054
&& (
1050
1055
node . parent . callee . name === 'forwardRef' || (
1051
1056
node . parent . callee . object
@@ -1055,9 +1060,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
1055
1060
)
1056
1061
)
1057
1062
) {
1058
- const propTypesParams = node . parent . typeParameters ;
1059
1063
const declaredPropTypes = { } ;
1060
- const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypesParams . params [ 1 ] , declaredPropTypes , rootNode ) ;
1064
+ const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypesArguments . params [ 1 ] , declaredPropTypes , rootNode ) ;
1061
1065
components . set ( node , {
1062
1066
declaredPropTypes : obj . declaredPropTypes ,
1063
1067
ignorePropsValidation : obj . shouldIgnorePropTypes ,
@@ -1103,7 +1107,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
1103
1107
if (
1104
1108
annotation
1105
1109
&& annotation . type !== 'TSTypeReference'
1106
- && annotation . typeParameters == null
1110
+ && propsUtil . getTypeArguments ( annotation ) == null
1107
1111
) {
1108
1112
return ;
1109
1113
}
0 commit comments