diff --git a/lib/util/ast.js b/lib/util/ast.js index 731a27330c..773cd65999 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -155,7 +155,7 @@ function stripQuotes(string) { * Retrieve the name of a key node * @param {Context} context The AST node with the key. * @param {ASTNode} node The AST node with the key. - * @return {string} the name of the key + * @return {string | undefined} the name of the key */ function getKeyValue(context, node) { if (node.type === 'ObjectTypeProperty') { @@ -172,6 +172,9 @@ function getKeyValue(context, node) { return; } const key = node.key || node.argument; + if (!key) { + return; + } return key.type === 'Identifier' ? key.name : key.value; } diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 7f1ec41835..e120d34f5f 100755 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -1650,6 +1650,17 @@ ruleTester.run('prop-types', rule, { '}' ].join('\n'), parser: parsers.BABEL_ESLINT + }, { + code: ` + type FooProps = { + ...any, + ...42, + } + function Foo(props: FooProps) { + return

; + } + `, + parser: parsers.BABEL_ESLINT }, { code: [ 'type Person = {',