diff --git a/lib/rules/require-default-props.js b/lib/rules/require-default-props.js index 410b8e0ff2..86aedc1c29 100644 --- a/lib/rules/require-default-props.js +++ b/lib/rules/require-default-props.js @@ -161,7 +161,12 @@ module.exports = { switch (node.typeAnnotation.type) { case 'GenericTypeAnnotation': var annotation = resolveGenericTypeAnnotation(node.typeAnnotation); - properties = annotation ? annotation.properties : []; + + if (annotation && annotation.id) { + annotation = findVariableByName(annotation.id.name); + } + + properties = annotation ? (annotation.properties || []) : []; break; case 'UnionTypeAnnotation': diff --git a/tests/lib/rules/require-default-props.js b/tests/lib/rules/require-default-props.js index 4ffe31c0de..1ccfe73837 100644 --- a/tests/lib/rules/require-default-props.js +++ b/tests/lib/rules/require-default-props.js @@ -677,6 +677,39 @@ ruleTester.run('require-default-props', rule, { '}' ].join('\n'), parser: 'babel-eslint' + }, + { + code: [ + 'import type ImportedProps from "fake";', + 'type Props = ImportedProps;', + 'function Hello(props: Props) {', + ' return
Hello {props.name.firstname}
;', + '}' + ].join('\n'), + parser: 'babel-eslint' + }, + // don't error when variable is not in scope + { + code: [ + 'import type { ImportedType } from "fake";', + 'type Props = ImportedType;', + 'function Hello(props: Props) {', + ' return
Hello {props.name.firstname}
;', + '}' + ].join('\n'), + parser: 'babel-eslint' + }, + // make sure error is not thrown with multiple assignments + { + code: [ + 'import type ImportedProps from "fake";', + 'type NestedProps = ImportedProps;', + 'type Props = NestedProps;', + 'function Hello(props: Props) {', + ' return
Hello {props.name.firstname}
;', + '}' + ].join('\n'), + parser: 'babel-eslint' } ],