Skip to content

Commit e05ce3c

Browse files
HenryBrown0ljharb
authored andcommitted
fix: use type args prop type util
1 parent 74baea5 commit e05ce3c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/util/propTypes.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
627627
typeName = node.typeName.name;
628628
const leftMostName = getLeftMostTypeName(node.typeName);
629629
const shouldTraverseTypeParams = genericReactTypesImport.has(leftMostName);
630-
const nodeTypeParams = node.typeParameters;
630+
const nodeTypeParams = node.typeArguments || node.typeParameters;
631631
if (shouldTraverseTypeParams && nodeTypeParams && nodeTypeParams.length !== 0) {
632632
// All react Generic types are derived from:
633633
// type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
@@ -728,7 +728,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
728728

729729
convertReturnTypeToPropTypes(node) {
730730
// ReturnType<T> should always have one parameter
731-
const nodeTypeParams = node.typeParameters;
731+
const nodeTypeParams = node.typeArguments || node.typeParameters;
732732
if (nodeTypeParams) {
733733
if (nodeTypeParams.params.length === 1) {
734734
let returnType = nodeTypeParams.params[0];
@@ -763,7 +763,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
763763
case 'ObjectExpression':
764764
iterateProperties(context, res.properties, (key, value, propNode) => {
765765
if (propNode && propNode.argument && propNode.argument.type === 'CallExpression') {
766-
const propNodeTypeParams = propNode.argument.typeParameters;
766+
const propNodeTypeParams = propNode.argument.typeArguments || propNode.argument.typeParameters;
767767
if (propNodeTypeParams) {
768768
this.visitTSNode(propNodeTypeParams);
769769
} else {
@@ -785,8 +785,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
785785
});
786786
break;
787787
case 'CallExpression':
788-
if (res.typeParameters) {
789-
this.visitTSNode(res.typeParameters);
788+
if (res.typeArguments || res.typeParameters) {
789+
this.visitTSNode(res.typeArguments || res.typeParameters);
790790
} else {
791791
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
792792
this.shouldIgnorePropTypes = true;
@@ -963,7 +963,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
963963
break;
964964
case 'GenericTypeAnnotation':
965965
if (propTypes.id.name === '$ReadOnly') {
966-
const propTypeParams = propTypes.typeParameters;
966+
const propTypeParams = propTypes.typeArguments || propTypes.typeParameters;
967967
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(
968968
propTypeParams.params[0],
969969
declaredPropTypes
@@ -1004,8 +1004,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
10041004
if (
10051005
node.parent
10061006
&& node.parent.callee
1007-
&& node.parent.typeParameters
1008-
&& node.parent.typeParameters.params
1007+
&& (
1008+
(node.parent.typeArguments && node.parent.typeArguments.params)
1009+
|| (node.parent.typeParameters && node.parent.typeParameters.params)
1010+
)
10091011
&& (
10101012
node.parent.callee.name === 'forwardRef' || (
10111013
node.parent.callee.object
@@ -1015,7 +1017,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
10151017
)
10161018
)
10171019
) {
1018-
const propTypesParams = node.parent.typeParameters;
1020+
const propTypesParams = node.parent.typeArguments || node.parent.typeParameters;
10191021
const declaredPropTypes = {};
10201022
const obj = new DeclarePropTypesForTSTypeAnnotation(propTypesParams.params[1], declaredPropTypes);
10211023
components.set(node, {
@@ -1063,7 +1065,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
10631065
if (
10641066
annotation
10651067
&& annotation.type !== 'TSTypeReference'
1066-
&& annotation.typeParameters == null
1068+
&& (annotation.typeArguments == null || annotation.typeParameters == null)
10671069
) {
10681070
return;
10691071
}

0 commit comments

Comments
 (0)