@@ -627,7 +627,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
627
627
typeName = node . typeName . name ;
628
628
const leftMostName = getLeftMostTypeName ( node . typeName ) ;
629
629
const shouldTraverseTypeParams = genericReactTypesImport . has ( leftMostName ) ;
630
- if ( shouldTraverseTypeParams && node . typeParameters && node . typeParameters . length !== 0 ) {
630
+ const nodeType = node . typeArguments || node . typeParameters ;
631
+ if ( shouldTraverseTypeParams && nodeType && nodeType . length !== 0 ) {
631
632
// All react Generic types are derived from:
632
633
// type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
633
634
// So we should construct an optional children prop
@@ -638,7 +639,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
638
639
const idx = genericTypeParamIndexWherePropsArePresent [
639
640
leftMostName !== rightMostName ? rightMostName : importedName
640
641
] ;
641
- const nextNode = node . typeParameters . params [ idx ] ;
642
+ const nextNode = nodeType . params [ idx ] ;
642
643
this . visitTSNode ( nextNode ) ;
643
644
return ;
644
645
}
@@ -727,9 +728,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
727
728
728
729
convertReturnTypeToPropTypes ( node ) {
729
730
// ReturnType<T> should always have one parameter
730
- if ( node . typeParameters ) {
731
- if ( node . typeParameters . params . length === 1 ) {
732
- let returnType = node . typeParameters . params [ 0 ] ;
731
+ const nodeType = node . typeArguments || node . typeParameters ;
732
+ if ( nodeType ) {
733
+ if ( nodeType . params . length === 1 ) {
734
+ let returnType = nodeType . params [ 0 ] ;
733
735
// This line is trying to handle typescript-eslint-parser
734
736
// typescript-eslint-parser TSTypeQuery is wrapped by TSTypeReference
735
737
if ( astUtil . isTSTypeReference ( returnType ) ) {
@@ -761,8 +763,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
761
763
case 'ObjectExpression' :
762
764
iterateProperties ( context , res . properties , ( key , value , propNode ) => {
763
765
if ( propNode && propNode . argument && propNode . argument . type === 'CallExpression' ) {
764
- if ( propNode . argument . typeParameters ) {
765
- this . visitTSNode ( propNode . argument . typeParameters ) ;
766
+ const propNodeType = propNode . argument . typeArguments || propNode . argument . typeParameters ;
767
+ if ( propNodeType ) {
768
+ this . visitTSNode ( propNodeType ) ;
766
769
} else {
767
770
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
768
771
this . shouldIgnorePropTypes = true ;
@@ -782,8 +785,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
782
785
} ) ;
783
786
break ;
784
787
case 'CallExpression' :
785
- if ( res . typeParameters ) {
786
- this . visitTSNode ( res . typeParameters ) ;
788
+ if ( res . typeArguments || res . typeParameters ) {
789
+ this . visitTSNode ( res . typeArguments || res . typeParameters ) ;
787
790
} else {
788
791
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
789
792
this . shouldIgnorePropTypes = true ;
@@ -960,8 +963,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
960
963
break ;
961
964
case 'GenericTypeAnnotation' :
962
965
if ( propTypes . id . name === '$ReadOnly' ) {
966
+ const propType = propTypes . typeArguments || propTypes . typeParameters ;
963
967
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation (
964
- propTypes . typeParameters . params [ 0 ] ,
968
+ propType . params [ 0 ] ,
965
969
declaredPropTypes
966
970
) ;
967
971
} else {
@@ -1000,8 +1004,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
1000
1004
if (
1001
1005
node . parent
1002
1006
&& node . parent . callee
1003
- && node . parent . typeParameters
1004
- && node . parent . typeParameters . params
1007
+ && (
1008
+ ( node . parent . typeArguments && node . parent . typeArguments . params )
1009
+ || ( node . parent . typeParameters && node . parent . typeParameters . params )
1010
+ )
1005
1011
&& (
1006
1012
node . parent . callee . name === 'forwardRef' || (
1007
1013
node . parent . callee . object
@@ -1011,9 +1017,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
1011
1017
)
1012
1018
)
1013
1019
) {
1014
- const propTypes = node . parent . typeParameters . params [ 1 ] ;
1020
+ const propTypes = node . parent . typeArguments || node . parent . typeParameters ;
1015
1021
const declaredPropTypes = { } ;
1016
- const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypes , declaredPropTypes ) ;
1022
+ const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypes . params [ 1 ] , declaredPropTypes ) ;
1017
1023
components . set ( node , {
1018
1024
declaredPropTypes : obj . declaredPropTypes ,
1019
1025
ignorePropsValidation : obj . shouldIgnorePropTypes ,
@@ -1059,7 +1065,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
1059
1065
if (
1060
1066
annotation
1061
1067
&& annotation . type !== 'TSTypeReference'
1062
- && annotation . typeParameters == null
1068
+ && ( annotation . typeArguments == null || annotation . typeParameters == null )
1063
1069
) {
1064
1070
return ;
1065
1071
}
0 commit comments