@@ -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 nodeTypeParams = node . typeParameters ;
631
+ if ( shouldTraverseTypeParams && nodeTypeParams && nodeTypeParams . 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 = nodeTypeParams . 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 nodeTypeParams = node . typeParameters ;
732
+ if ( nodeTypeParams ) {
733
+ if ( nodeTypeParams . params . length === 1 ) {
734
+ let returnType = nodeTypeParams . 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 propNodeTypeParams = propNode . argument . typeParameters ;
767
+ if ( propNodeTypeParams ) {
768
+ this . visitTSNode ( propNodeTypeParams ) ;
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 ;
@@ -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 propTypeParams = propTypes . typeParameters ;
963
967
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation (
964
- propTypes . typeParameters . params [ 0 ] ,
968
+ propTypeParams . params [ 0 ] ,
965
969
declaredPropTypes
966
970
) ;
967
971
} else {
@@ -1011,9 +1015,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
1011
1015
)
1012
1016
)
1013
1017
) {
1014
- const propTypes = node . parent . typeParameters . params [ 1 ] ;
1018
+ const propTypesParams = node . parent . typeParameters ;
1015
1019
const declaredPropTypes = { } ;
1016
- const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypes , declaredPropTypes ) ;
1020
+ const obj = new DeclarePropTypesForTSTypeAnnotation ( propTypesParams . params [ 1 ] , declaredPropTypes ) ;
1017
1021
components . set ( node , {
1018
1022
declaredPropTypes : obj . declaredPropTypes ,
1019
1023
ignorePropsValidation : obj . shouldIgnorePropTypes ,
0 commit comments