Skip to content

Commit 5bd75c9

Browse files
committed
[Fix] super type parameter resolving in newer @typescript-eslint/parser versions
1 parent d4ac812 commit 5bd75c9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/util/propTypes.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function isFunctionType(node) {
4141
*/
4242
function isSuperTypeParameterPropsDeclaration(node) {
4343
if (node && (node.type === 'ClassDeclaration' || node.type === 'ClassExpression')) {
44-
if (node.superTypeParameters && node.superTypeParameters.params.length > 0) {
44+
const parameters = node.superTypeParameters || node.superTypeArguments;
45+
if (parameters && parameters.params.length > 0) {
4546
return true;
4647
}
4748
}
@@ -1119,23 +1120,25 @@ module.exports = function propTypesInstructions(context, components, utils) {
11191120
}
11201121

11211122
/**
1122-
* Resolve the type annotation for a given class declaration node with superTypeParameters.
1123+
* Resolve the type annotation for a given class declaration node.
11231124
*
11241125
* @param {ASTNode} node The annotation or a node containing the type annotation.
11251126
* @returns {ASTNode} The resolved type annotation for the node.
11261127
*/
11271128
function resolveSuperParameterPropsType(node) {
11281129
let propsParameterPosition;
1130+
const parameters = node.superTypeParameters || node.superTypeArguments;
1131+
11291132
try {
11301133
// Flow <=0.52 had 3 required TypedParameters of which the second one is the Props.
11311134
// Flow >=0.53 has 2 optional TypedParameters of which the first one is the Props.
11321135
propsParameterPosition = testFlowVersion(context, '>= 0.53.0') ? 0 : 1;
11331136
} catch (e) {
11341137
// In case there is no flow version defined, we can safely assume that when there are 3 Props we are dealing with version <= 0.52
1135-
propsParameterPosition = node.superTypeParameters.params.length <= 2 ? 0 : 1;
1138+
propsParameterPosition = parameters.params.length <= 2 ? 0 : 1;
11361139
}
11371140

1138-
let annotation = node.superTypeParameters.params[propsParameterPosition];
1141+
let annotation = parameters.params[propsParameterPosition];
11391142
while (annotation && (annotation.type === 'TypeAnnotation' || annotation.type === 'NullableTypeAnnotation')) {
11401143
annotation = annotation.typeAnnotation;
11411144
}

0 commit comments

Comments
 (0)