diff --git a/lib/rules/prefer-read-only-props.js b/lib/rules/prefer-read-only-props.js index 8349435f24..3a1faff94a 100644 --- a/lib/rules/prefer-read-only-props.js +++ b/lib/rules/prefer-read-only-props.js @@ -13,7 +13,7 @@ function isFlowPropertyType(node) { } function isCovariant(node) { - return node.variance && node.variance.kind === 'plus'; + return node.variance && node.variance.kind === 'plus' || node.parent.parent.parent.id && node.parent.parent.parent.id.name === '$ReadOnly'; } // ------------------------------------------------------------------------------ diff --git a/tests/lib/rules/prefer-read-only-props.js b/tests/lib/rules/prefer-read-only-props.js index 9445605c68..dbdfda6a10 100644 --- a/tests/lib/rules/prefer-read-only-props.js +++ b/tests/lib/rules/prefer-read-only-props.js @@ -131,6 +131,19 @@ ruleTester.run('prefer-read-only-props', rule, { name: PropTypes.string, }; ` + }, + // Class component with typed props property wrapped in $ReadOnly + { + code: [ + 'type Props = $ReadOnly<{foo: number}>;', + 'class Hello extends React.Component {', + ' props: Props;', + ' render () {', + ' return
{this.props.foo}
;', + ' }', + '}' + ].join('\n'), + parser: parsers.BABEL_ESLINT } ],