diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index 00fc1b2ba2..eec5cc4f08 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -300,6 +300,17 @@ module.exports = { return tokens.length && tokens[0].value === '...'; } + /** + * Removes quotes from around an identifier. + * @param {string} the identifier to strip + */ + function stripQuotes(string) { + if (string[0] === '\'' || string[0] === '"' && string[0] === string[string.length - 1]) { + return string.slice(1, string.length - 1); + } + return string; + } + /** * Retrieve the name of a key node * @param {ASTNode} node The AST node with the key. @@ -310,7 +321,7 @@ module.exports = { var tokens = context.getFirstTokens(node, 2); return (tokens[0].value === '+' || tokens[0].value === '-' ? tokens[1].value - : tokens[0].value + : stripQuotes(tokens[0].value) ); } var key = node.key || node.argument; diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 9649f57eef..bd00fca966 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -1105,6 +1105,16 @@ ruleTester.run('prop-types', rule, { '}' ].join('\n'), parser: 'babel-eslint' + }, { + code: [ + 'type Props = {', + ' \'completed?\': boolean,', + '};', + 'const Hello = (props: Props): React.Element => {', + ' return
{props[\'completed?\']}
;', + '}' + ].join('\n'), + parser: 'babel-eslint' }, { code: [ 'Card.propTypes = {',