@@ -639,8 +639,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
639639 typeName = node . typeName . name ;
640640 const leftMostName = getLeftMostTypeName ( node . typeName ) ;
641641 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 ) {
644644 // All react Generic types are derived from:
645645 // type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
646646 // So we should construct an optional children prop
@@ -662,7 +662,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
662662 const idx = genericTypeParamIndexWherePropsArePresent [
663663 leftMostName !== rightMostName ? rightMostName : importedName
664664 ] ;
665- const nextNode = nodeTypeParams . params [ idx ] ;
665+ const nextNode = nodeTypeArguments . params [ idx ] ;
666666 this . visitTSNode ( nextNode ) ;
667667 return ;
668668 }
@@ -759,10 +759,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
759759
760760 convertReturnTypeToPropTypes ( node , rootNode ) {
761761 // 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 ] ;
766766 // This line is trying to handle typescript-eslint-parser
767767 // typescript-eslint-parser TSTypeQuery is wrapped by TSTypeReference
768768 if ( astUtil . isTSTypeReference ( returnType ) ) {
@@ -794,9 +794,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
794794 case 'ObjectExpression' :
795795 iterateProperties ( context , res . properties , ( key , value , propNode ) => {
796796 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 ) ;
800800 } else {
801801 // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
802802 this . shouldIgnorePropTypes = true ;
@@ -816,8 +816,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
816816 } ) ;
817817 break ;
818818 case 'CallExpression' :
819- if ( res . typeParameters ) {
820- this . visitTSNode ( res . typeParameters ) ;
819+ if ( propsUtil . getTypeArguments ( res ) ) {
820+ this . visitTSNode ( propsUtil . getTypeArguments ( res ) ) ;
821821 } else {
822822 // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
823823 this . shouldIgnorePropTypes = true ;
@@ -1002,9 +1002,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
10021002 break ;
10031003 case 'GenericTypeAnnotation' :
10041004 if ( propTypes . id . name === '$ReadOnly' ) {
1005- const propTypeParams = propTypes . typeParameters ;
1005+ const propTypeArguments = propsUtil . getTypeArguments ( propTypes ) ;
10061006 ignorePropsValidation = declarePropTypesForObjectTypeAnnotation (
1007- propTypeParams . params [ 0 ] ,
1007+ propTypeArguments . params [ 0 ] ,
10081008 declaredPropTypes
10091009 ) ;
10101010 } else {
@@ -1041,11 +1041,16 @@ module.exports = function propTypesInstructions(context, components, utils) {
10411041 return ;
10421042 }
10431043
1044+ let propTypesArguments = null ;
1045+ if ( node . parent ) {
1046+ propTypesArguments = propsUtil . getTypeArguments ( node . parent ) ;
1047+ }
1048+
10441049 if (
10451050 node . parent
10461051 && node . parent . callee
1047- && node . parent . typeParameters
1048- && node . parent . typeParameters . params
1052+ && propTypesArguments
1053+ && propTypesArguments . params
10491054 && (
10501055 node . parent . callee . name === 'forwardRef' || (
10511056 node . parent . callee . object
@@ -1055,9 +1060,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
10551060 )
10561061 )
10571062 ) {
1058- const propTypesParams = node . parent . typeParameters ;
10591063 const declaredPropTypes = { } ;
1060- const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypesParams . params [ 1 ] , declaredPropTypes , rootNode ) ;
1064+ const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypesArguments . params [ 1 ] , declaredPropTypes , rootNode ) ;
10611065 components . set ( node , {
10621066 declaredPropTypes : obj . declaredPropTypes ,
10631067 ignorePropsValidation : obj . shouldIgnorePropTypes ,
@@ -1103,7 +1107,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
11031107 if (
11041108 annotation
11051109 && annotation . type !== 'TSTypeReference'
1106- && annotation . typeParameters == null
1110+ && propsUtil . getTypeArguments ( annotation ) == null
11071111 ) {
11081112 return ;
11091113 }
0 commit comments