Skip to content

Commit

Permalink
fix: use type args prop type util
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryBrown0 authored and ljharb committed Sep 4, 2023
1 parent 74baea5 commit e05ce3c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
typeName = node.typeName.name;
const leftMostName = getLeftMostTypeName(node.typeName);
const shouldTraverseTypeParams = genericReactTypesImport.has(leftMostName);
const nodeTypeParams = node.typeParameters;
const nodeTypeParams = node.typeArguments || node.typeParameters;
if (shouldTraverseTypeParams && nodeTypeParams && nodeTypeParams.length !== 0) {
// All react Generic types are derived from:
// type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
Expand Down Expand Up @@ -728,7 +728,7 @@ module.exports = function propTypesInstructions(context, components, utils) {

convertReturnTypeToPropTypes(node) {
// ReturnType<T> should always have one parameter
const nodeTypeParams = node.typeParameters;
const nodeTypeParams = node.typeArguments || node.typeParameters;
if (nodeTypeParams) {
if (nodeTypeParams.params.length === 1) {
let returnType = nodeTypeParams.params[0];
Expand Down Expand Up @@ -763,7 +763,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
case 'ObjectExpression':
iterateProperties(context, res.properties, (key, value, propNode) => {
if (propNode && propNode.argument && propNode.argument.type === 'CallExpression') {
const propNodeTypeParams = propNode.argument.typeParameters;
const propNodeTypeParams = propNode.argument.typeArguments || propNode.argument.typeParameters;
if (propNodeTypeParams) {
this.visitTSNode(propNodeTypeParams);
} else {
Expand All @@ -785,8 +785,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
});
break;
case 'CallExpression':
if (res.typeParameters) {
this.visitTSNode(res.typeParameters);
if (res.typeArguments || res.typeParameters) {
this.visitTSNode(res.typeArguments || res.typeParameters);
} else {
// Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
this.shouldIgnorePropTypes = true;
Expand Down Expand Up @@ -963,7 +963,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
break;
case 'GenericTypeAnnotation':
if (propTypes.id.name === '$ReadOnly') {
const propTypeParams = propTypes.typeParameters;
const propTypeParams = propTypes.typeArguments || propTypes.typeParameters;
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(
propTypeParams.params[0],
declaredPropTypes
Expand Down Expand Up @@ -1004,8 +1004,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
if (
node.parent
&& node.parent.callee
&& node.parent.typeParameters
&& node.parent.typeParameters.params
&& (
(node.parent.typeArguments && node.parent.typeArguments.params)
|| (node.parent.typeParameters && node.parent.typeParameters.params)
)
&& (
node.parent.callee.name === 'forwardRef' || (
node.parent.callee.object
Expand All @@ -1015,7 +1017,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
)
)
) {
const propTypesParams = node.parent.typeParameters;
const propTypesParams = node.parent.typeArguments || node.parent.typeParameters;
const declaredPropTypes = {};
const obj = new DeclarePropTypesForTSTypeAnnotation(propTypesParams.params[1], declaredPropTypes);
components.set(node, {
Expand Down Expand Up @@ -1063,7 +1065,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
if (
annotation
&& annotation.type !== 'TSTypeReference'
&& annotation.typeParameters == null
&& (annotation.typeArguments == null || annotation.typeParameters == null)
) {
return;
}
Expand Down

0 comments on commit e05ce3c

Please sign in to comment.