diff --git a/lib/rules/destructuring-assignment.js b/lib/rules/destructuring-assignment.js index b4aa3da159..d537cca3b9 100644 --- a/lib/rules/destructuring-assignment.js +++ b/lib/rules/destructuring-assignment.js @@ -257,6 +257,7 @@ module.exports = { if (!propsRefs) { return; } + // Skip if props is used elsewhere if (propsRefs.length > 1) { return; diff --git a/tests/lib/rules/destructuring-assignment.js b/tests/lib/rules/destructuring-assignment.js index e1f8e85b08..80bf99dd7d 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -872,6 +872,41 @@ ${' '} `, features: ['ts', 'no-babel'], }, - ] : [] + ] : [], + { + code: ` + type Props = { text: string }; + export const MyComponent: React.FC = (props) => { + type MyType = typeof props.text; + return
{props.text as MyType}
; + }; + `, + options: ['always', { destructureInSignature: 'always' }], + features: ['types'], + errors: [ + { + messageId: 'useDestructAssignment', + data: { type: 'props' }, + }, + ], + }, + { + code: ` + type Props = { text: string }; + export const MyOtherComponent: React.FC = (props) => { + const { text } = props; + type MyType = typeof props.text; + return
{text as MyType}
; + }; + `, + options: ['always', { destructureInSignature: 'always' }], + features: ['types'], + errors: [ + { + messageId: 'destructureInSignature', + data: { type: 'props' }, + }, + ], + } )), });