@@ -637,8 +637,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
637
637
typeName = node . typeName . name ;
638
638
const leftMostName = getLeftMostTypeName ( node . typeName ) ;
639
639
const shouldTraverseTypeParams = genericReactTypesImport . has ( leftMostName ) ;
640
- const nodeTypeParams = node . typeArguments || node . typeParameters ;
641
- if ( shouldTraverseTypeParams && nodeTypeParams && nodeTypeParams . length !== 0 ) {
640
+ const nodeTypeArguments = propsUtil . getTypeArguments ( node ) ;
641
+ if ( shouldTraverseTypeParams && nodeTypeArguments && nodeTypeArguments . length !== 0 ) {
642
642
// All react Generic types are derived from:
643
643
// type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
644
644
// So we should construct an optional children prop
@@ -660,7 +660,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
660
660
const idx = genericTypeParamIndexWherePropsArePresent [
661
661
leftMostName !== rightMostName ? rightMostName : importedName
662
662
] ;
663
- const nextNode = nodeTypeParams . params [ idx ] ;
663
+ const nextNode = nodeTypeArguments . params [ idx ] ;
664
664
this . visitTSNode ( nextNode ) ;
665
665
return ;
666
666
}
@@ -749,10 +749,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
749
749
750
750
convertReturnTypeToPropTypes ( node , rootNode ) {
751
751
// ReturnType<T> should always have one parameter
752
- const nodeTypeParams = node . typeArguments || node . typeParameters ;
753
- if ( nodeTypeParams ) {
754
- if ( nodeTypeParams . params . length === 1 ) {
755
- let returnType = nodeTypeParams . params [ 0 ] ;
752
+ const nodeTypeArguments = propsUtil . getTypeArguments ( node ) ;
753
+ if ( nodeTypeArguments ) {
754
+ if ( nodeTypeArguments . params . length === 1 ) {
755
+ let returnType = nodeTypeArguments . params [ 0 ] ;
756
756
// This line is trying to handle typescript-eslint-parser
757
757
// typescript-eslint-parser TSTypeQuery is wrapped by TSTypeReference
758
758
if ( astUtil . isTSTypeReference ( returnType ) ) {
@@ -784,10 +784,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
784
784
case 'ObjectExpression' :
785
785
iterateProperties ( context , res . properties , ( key , value , propNode ) => {
786
786
if ( propNode && propNode . argument && propNode . argument . type === 'CallExpression' ) {
787
- const propNodeTypeParams = propNode . argument . typeArguments
788
- || propNode . argument . typeParameters ;
789
- if ( propNodeTypeParams ) {
790
- this . visitTSNode ( propNodeTypeParams ) ;
787
+ const propNodeTypeArguments = propsUtil . getTypeArguments ( propNode . argument ) ;
788
+ if ( propNodeTypeArguments ) {
789
+ this . visitTSNode ( propNodeTypeArguments ) ;
791
790
} else {
792
791
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
793
792
this . shouldIgnorePropTypes = true ;
@@ -807,8 +806,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
807
806
} ) ;
808
807
break ;
809
808
case 'CallExpression' :
810
- if ( res . typeArguments || res . typeParameters ) {
811
- this . visitTSNode ( res . typeArguments || res . typeParameters ) ;
809
+ if ( propsUtil . getTypeArguments ( res ) ) {
810
+ this . visitTSNode ( propsUtil . getTypeArguments ( res ) ) ;
812
811
} else {
813
812
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
814
813
this . shouldIgnorePropTypes = true ;
@@ -993,9 +992,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
993
992
break ;
994
993
case 'GenericTypeAnnotation' :
995
994
if ( propTypes . id . name === '$ReadOnly' ) {
996
- const propTypeParams = propTypes . typeArguments || propTypes . typeParameters ;
995
+ const propTypeArguments = propsUtil . getTypeArguments ( propTypes ) ;
997
996
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation (
998
- propTypeParams . params [ 0 ] ,
997
+ propTypeArguments . params [ 0 ] ,
999
998
declaredPropTypes
1000
999
) ;
1001
1000
} else {
@@ -1032,13 +1031,16 @@ module.exports = function propTypesInstructions(context, components, utils) {
1032
1031
return ;
1033
1032
}
1034
1033
1034
+ let propTypesArguments = null ;
1035
+ if ( node . parent ) {
1036
+ propTypesArguments = propsUtil . getTypeArguments ( node . parent ) ;
1037
+ }
1038
+
1035
1039
if (
1036
1040
node . parent
1037
1041
&& node . parent . callee
1038
- && (
1039
- ( node . parent . typeArguments && node . parent . typeArguments . params )
1040
- || ( node . parent . typeParameters && node . parent . typeParameters . params )
1041
- )
1042
+ && propTypesArguments
1043
+ && propTypesArguments . params
1042
1044
&& (
1043
1045
node . parent . callee . name === 'forwardRef' || (
1044
1046
node . parent . callee . object
@@ -1048,9 +1050,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
1048
1050
)
1049
1051
)
1050
1052
) {
1051
- const propTypesParams = node . parent . typeArguments || node . parent . typeParameters ;
1052
1053
const declaredPropTypes = { } ;
1053
- const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypesParams . params [ 1 ] , declaredPropTypes , rootNode ) ;
1054
+ const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypesArguments . params [ 1 ] , declaredPropTypes , rootNode ) ;
1054
1055
components . set ( node , {
1055
1056
declaredPropTypes : obj . declaredPropTypes ,
1056
1057
ignorePropsValidation : obj . shouldIgnorePropTypes ,
@@ -1096,7 +1097,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
1096
1097
if (
1097
1098
annotation
1098
1099
&& annotation . type !== 'TSTypeReference'
1099
- && ( annotation . typeArguments == null || annotation . typeParameters == null )
1100
+ && propsUtil . getTypeArguments ( annotation ) == null
1100
1101
) {
1101
1102
return ;
1102
1103
}
0 commit comments