Skip to content

Commit 887c3b0

Browse files
committed
Fix require-default-props rule when using Flow type from assignment
1 parent a33db3b commit 887c3b0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/rules/require-default-props.js

+5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ module.exports = {
141141
switch (node.typeAnnotation.type) {
142142
case 'GenericTypeAnnotation':
143143
var annotation = resolveGenericTypeAnnotation(node.typeAnnotation);
144+
145+
if (annotation && annotation.id) {
146+
annotation = findVariableByName(annotation.id.name);
147+
}
148+
144149
properties = annotation ? annotation.properties : [];
145150
break;
146151

tests/lib/rules/require-default-props.js

+10
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,16 @@ ruleTester.run('require-default-props', rule, {
676676
'}'
677677
].join('\n'),
678678
parser: 'babel-eslint'
679+
},
680+
{
681+
code: [
682+
'import type ImportedProps from "fake";',
683+
'type Props = ImportedProps;',
684+
'function Hello(props: Props) {',
685+
' return <div>Hello {props.name.firstname}</div>;',
686+
'}'
687+
].join('\n'),
688+
parser: 'babel-eslint'
679689
}
680690
],
681691

0 commit comments

Comments
 (0)